Dain1234 / Java-Programming

0 stars 0 forks source link

Sum of n digit number #33

Open Dain1234 opened 1 year ago

Dain1234 commented 1 year ago

package com.dain.logics;

import java.util.Scanner;

public class SumOfNdigitNumber { public static void main(String[] args) { int sum = 0; Scanner sc = new Scanner(System.in); System.out.println("Enter the number:"); int num = sc.nextInt(); while (num != 0) {

        int rem = num % 10;
        sum = sum + rem;
        num = num / 10;

    }
    System.out.println("sum of number  " + sum);

}

}