java控制数字位数
Here you will get java program to find sum of digits of a number. For example if given digit is 125 then its sum will be 8.
在这里,您将获得一个Java程序来查找数字的总和。 例如,如果给定数字为125,则其总和为8。
class sum
{
public static void main(String...s)
{
int n,i,sum=0;
n=Integer.parseInt(s[0]);
while(n!=0)
{
i=n%10;
sum+=i;
n/=10;
}
System.out.println(sum);
}
}
Output
输出量
翻译自: https://www.thecrazyprogrammer.com/2013/08/java-program-to-find-sum-of-digits-of.html
java控制数字位数