如何在java中打印给定整数a = 1234的最后两位数字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20947260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:29:38  来源:igfitidea点击:

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

java

提问by Mani Beginner

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

如果我给出像 a=1234 这样的值,我只想打印最后两位数字 34 .. 谁能给我解决方案...

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

回答by Jigar Joshi

number % 100will result in last 2 digit

number % 100将导致最后 2 位数字

See

回答by user3162144

User modulo 100

用户模 100

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

回答by Ruchira Gayan Ranaweera

You can try this too

你也可以试试这个

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

Out put

输出

34