Calculates the sum of the digits in the digits of an integer

Calculates the sum of the digits in the digits of an integer.
Input
Input an integer
Output
Output the sum of the digits on each digit
Sample input
123

Sample output
6

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n;
        int sum=0;
        Scanner scan=new Scanner(System.in);
        n=scan.nextInt();
        while(n/10!=0)
        {
            sum=sum+n%10;
            n=n/10;
        }
        sum=sum+n;
        System.out.println(sum);
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325190607&siteId=291194637