import java.util.Scanner;
public class number
{ public static int sum(long n){
int sum=0;
while(n>0){
int m=(int)(n%10);
sum=sum+m;
n=n/10;
}
return sum;
} public static void main(String[] args){
try{
System.out.println("请输入数字:");
Scanner sc=new Scanner(System.in);
long l=sc.nextLong();
System.out.println(+sum(l));
}catch(Exception e){
}
}
}
java第三次作业
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)