Saturday, 28 November 2015

PROGRAM TO CALCULATE GENERATE A 5DIGIT NUMBER AND FINDING SUM OF ITS DIGIT

//Program to calculate generate a 5digit number and finding sum of its digit
class Sum
{
public static void main(String args[])
{
int num1,num=(int)(Math.random()*100000);
num1=num;
int sum=0,rem=0;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
System.out.println(“Sum of digits of “+num1+” is “+sum);
}
}

No comments:

Post a Comment