public class SingleNumber {
public void m1()
{
System.out.println("hai");
}
public static void main(String[] args) {
int num=99998,sum=0;
while(num>9)
{
sum=0;
while(num!=0)
{
int r=num%10;
sum=sum+r;
num=num/10;
}
num=sum;
}
System.out.println(sum);
}
}
Save and run this program u will get out put as shown below:
8
public void m1()
{
System.out.println("hai");
}
public static void main(String[] args) {
int num=99998,sum=0;
while(num>9)
{
sum=0;
while(num!=0)
{
int r=num%10;
sum=sum+r;
num=num/10;
}
num=sum;
}
System.out.println(sum);
}
}
Save and run this program u will get out put as shown below:
8
No comments:
Post a Comment