Write A Java Program To Diplay All Happy Number Within 100
class HappyNo
{
static boolean isHappy(int n)
{
while(n>9)
{
int sum=0;
do
{
int r=n%10;
sum=sum+r*r;
n=n/10;
}
while (n!=0);
n=sum;
}
return n==1||n==7;
}
public static void main(String[] args)
{
//Scanner sc=new Scanner(System.in);
System.out.println("\n\n\t\tHappy Number Within 100\n\t\t");
for(int i=1;i<=100;i++)
{
boolean rs=isHappy(i);
if(rs)
System.out.print(i+" ");
}
System.out.print("\n\n ");
}
}
OUTPUT
OUTPUT
This Java program for finding happy numbers is a fun way to explore number theory! If you're interested in enhancing your coding skills, check out hostingmella for some great resources and tutorials.
ReplyDelete