Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

sum of digits java

   public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();

        int sum = 0;

        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
        System.out.println("sum of digits: " + sum);
    }
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #sum #digits #java
ADD COMMENT
Topic
Name
9+5 =