输入一个整数,计算各个数位上数的和
/*输入一个整数,求出该整数的各个位置数字之和*/
import java.util.Scanner;
public class HomeWorkDay004_Sum {
public static void main(String[] args) {
System.out.println("请输入数字");
Scanner scanner = new Scanner(System.in);
int num =scanner.nextInt();
int singleNum= 0;
int sum = 0;
for (int i = 0; i <10 ; i++) {
if (num%10==0){
break;
}else {
singleNum = num % 10;
num = num/10;
sum+=singleNum;
}
}
System.out.println("各个位置之上的数字之和为"+sum);
}
}