import java.util.Scanner;
/**
* 用JAVA求任意一个数的各个位数之和
* @author Administrator
*
*/
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个数字:");
int num = sc.nextInt();
int sum=0;
while(num!=0){
sum = sum + num%10;
num = num/10;
}
System.out.println("所给数字的各个位数之和为:"+sum);
}
}
Java求出任意数字的各个位数之和
最新推荐文章于 2022-10-27 16:05:52 发布