Write a Java program to accept a positive number and repeatedly add all its digits until the result has only one digit.
/* Write a Java program to accept a positive number and repeatedly add all its digits
until the result has only one digit. */
import java.util.*;
class Twelve
{
public static void main(String arg[])
{
Scanner obj = new Scanner(System.in);
int no;
System.out.print("\nEnter any positive number :");
no = obj.nextInt();
if(no != 0)
{
while(no > 9)
{
int b = 0;
while(no != 0)
{
b += no % 10;
no /= 10;
}
no = b;
}
}
System.out.println("sum : " + no);
}
}
More Information on our channel Programmer Community
please like , share and subscribe to get notifications of new videos....
To understand this program video will coming soon on our you tube channel
Comments
Post a Comment