//Find out if a program is a happy no. or not.
import java.util.*;
class Happy
{
public void conti(int n)
{
int digits;
int copy=n;
boolean flag=false;
do
{
int s=0;
digits=0;
while(n>0)
{
int dg=n%10;
s=s+dg*dg;
n=n/10;
}
System.out.println("Sum = " + s);
for(int i=s;i>0;i=i/10)
digits++;
System.out.print("Digits " + digits);
if(s==1)
flag=true;
n=s;
}while(digits>1);
if(n==1)
System.out.println("Happy no. is " +copy);
}
}
No comments:
Post a Comment
Convey your thoughts to authors.