Code Below:
import java.util.*;
class happy
{
public static void main()
{
Scanner s=new Scanner(System.in);
int n,x,sum,i,digit;
System.out.println("enter a no.");
n=s.nextInt();
if(n==1||n==7)
System.out.println("happy no.");
for(x=n;x>=10;x=sum)
{
sum=0;
i=x;
while(i>0)
{
digit=i%10;
sum=sum+digit*digit;
i=i/10;
}
}
if(x==1)
System.out.println("happy no.");
}
}