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 );
    }

 

相关文章:

  • 2021-05-29
  • 2022-01-14
  • 2021-04-04
  • 2021-12-18
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2021-07-31
  • 2021-07-01
  • 2021-11-23
相关资源
相似解决方案