Write a program that inputs a five-digit number and calculates the sum of its digit.

 

public static void main(String[] args) {

Scanner cin= new Scanner(System.in);

int n,a,b,c,d,sum;

System.out.println(“Enter 5 digit number”);

n=cin.nextInt();

a=n/10000;

n=n%10000;

b=n/1000;

n=n%1000;

c=n/100;

n=n%100;

d=n/10;

n=n%10;

sum=a+b+c+d+n;

System.out.println(“Sum= Of Digit=”+sum);

}

}

Output

run:
Enter 5 digit number
4123
Sum= Of Digit=10
BUILD SUCCESSFUL (total time: 5 seconds)

Leave a Reply

Your email address will not be published. Required fields are marked *