package com.tutorial4u;
import java.util.Scanner;
public class SumOfDigit {
public static void main(String[] args) {
int num,sum=0 ,rem;
System.out.print("Enter any number to add : ");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
while(num!=0){
rem = num %10;
num = num/10;
sum = sum+rem;
}
System.out.println("Sum of digit is : "+sum);
}
}
Enter
any number to add : 12345
Sum of
digit is : 15
No comments:
Post a Comment