Java - Happy Number Program.
Happy Number Program.
import java.util.Scanner;
class HappyNum
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Number");
int num=sc.nextInt();
int rem=0;
int sqr=0;
while(num>9)
{
int sum=0;
while(num>0)
{
rem=num%10;
sqr=rem*rem;
sum=sum+sqr;
num=num/10;
}
num=sum;
}
if(num==1)
{
System.out.println("Happy Number");
}
else
{
System.out.println("Not Happy");
}
}
}