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

If I give values ​​like a = 1234, I want to print only the last two digits 34. Can someone give me a solution for this ...

int a=1234;
System.out.print(a);
+4
source share
3 answers

number % 100 will result in the last two digits

Cm

+11
source

User modulo 100

System.out.print(String.format("%02d", (abs(a)%100)));
+7
source

You can try it too

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

Out put

34
+3
source

All Articles