标签:
public static long sumDigits(long n){ long total=0; long number=n; while(number!=0){ total=total+number%10; number=(number-number%10)/10; } return total; } public static void testSumDigits(){ System.out.println("Enter a long integer: "); Scanner input=new Scanner(System.in); long n=input.nextLong(); long result=sumDigits(n); System.out.print("The sum of every number of the integer is:"+ result ); }
标签:
原文地址:http://www.cnblogs.com/xingzhui/p/5700191.html