Program to add unit of given number in java programming.


Program to add unit of given number in java programming:
import java.io.*;
import java.util.*;
import java.lang.*;
class AddUnitNum
{
public static void main(String[] str)
{
Scanner s= new Scanner(System.in);
int  num,sum=0;
System.out.println("            www.a3programming.blogspot.com");
System.out.println("Enter number sir:");
num=s.nextInt();
while(num!=0)
{
sum=sum+num%10;
num=num/10;
}
System.out.println("Sum ="+sum);
System.out.println("Good Bye");

}
}

Expected output is:

Post a Comment

3 Comments