import java.util.Scanner;public class add { public static int sumDigits(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("输入数字的各位数之和为"+sumDigits(l)); }catch(Exception e){ System.out.println("您输入的不是数字!"); } }}