How to print last two digits of given integer a=1234 in java

前端 未结 3 768
無奈伤痛
無奈伤痛 2021-01-04 23:57

If i\'m giving values like a=1234, i want to print last two digits 34 only.. can anyone give me solution for this...

int a=1234;
System.out.print(a);
         


        
相关标签:
3条回答
  • 2021-01-05 00:20

    number % 100 will result in last 2 digit

    See

    • ideone demo
    0 讨论(0)
  • 2021-01-05 00:20

    User modulo 100

    System.out.print(String.format("%02d", (abs(a)%100)));
    
    0 讨论(0)
  • 2021-01-05 00:27

    You can try this too

    int a=1234;
    System.out.print(String.valueOf(a).substring(2));
    

    Out put

    34
    
    0 讨论(0)
提交回复
热议问题