NEON NUMBER:
A neon number is a number where the sum of digits of square of the number is equal to the number. For example if the input number is 9, its square is 9*9 = 81 and sum of the digits is 9. i.e. 9 is a neon number.
There are only 3 neon numbers. they are 0,1,9
/*Program for checking given number is neon number or not*/
import java.util.*;
public class NeonNumber
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the number to check neon number or not");
int num=ob.nextInt();
int square=num*num;
int sum=0;
while(square!=0)//Loop to find the sum of digits.
{
int a=square%10;
sum=sum+a;
square=square/10;
}
if(sum==num)
{
System.out.println(num+" is a Neon Number.");
}
else
{
System.out.println(num+" is not a Neon Number.");
}
}
}
OUTPUT:
Enter the number to check neon number or not
9
9 is a Neon Number.
Enter the number to check neon number or not
8
8 is not a Neon Number.
A neon number is a number where the sum of digits of square of the number is equal to the number. For example if the input number is 9, its square is 9*9 = 81 and sum of the digits is 9. i.e. 9 is a neon number.
There are only 3 neon numbers. they are 0,1,9
/*Program for checking given number is neon number or not*/
import java.util.*;
public class NeonNumber
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the number to check neon number or not");
int num=ob.nextInt();
int square=num*num;
int sum=0;
while(square!=0)//Loop to find the sum of digits.
{
int a=square%10;
sum=sum+a;
square=square/10;
}
if(sum==num)
{
System.out.println(num+" is a Neon Number.");
}
else
{
System.out.println(num+" is not a Neon Number.");
}
}
}
OUTPUT:
Enter the number to check neon number or not
9
9 is a Neon Number.
Enter the number to check neon number or not
8
8 is not a Neon Number.
No comments:
Post a Comment