Jun 3, 2017

Java program to find SUM of the Number

import java.io.*;
class sumdigits
{
public static void main(String args[]) throws IOException
{
int num,rem,sum=0;
DataInputStream s=new DataInputStream(System.in);
System.out.println("enter the number as u wish");
num=Integer.parseInt(s.readLine());
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
System.out.println("the sum of numbers is "+sum);
}
}

No comments:

Post a Comment