import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args)
{
//System.out.println("Hello java");
Scanner s = new Scanner(System.in);
System.out.println("请输入一个数字");
int num = s.nextInt();
int sum = 0 ;
while(num != 0)
{
sum += num % 10 ;
num /= 10 ;
}
System.out.println("sum:"+sum);
}
}
java实现:将一个数各个位数相加
最新推荐文章于 2022-12-24 00:45:07 发布