2.6 求一个整数各位数的和-java
package chapter01;
import java.util.Scanner;
public class DigitsSum {
public static void main(String[] args) {
System.out.print("Please input a number: ");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
int temp = number;
int sum = 0;
while(temp!=0)
{
sum += temp%10;
temp = temp/10;
}
System.out.print("The reasult is "+sum);
}
}