Home »
Java programs
Java program to check Neon number
In this java program, we are going to check whether a given number is Neon number or not? A number is a Neon number, if sum of the digits of square of a number is equal to the number itself.
Submitted by IncludeHelp, on October 29, 2017
Given a number, and we have to check whether it is Neon number or not using Java program.
Neon Number
A number is a Neon number, if sum of the digits of square of a number is equal to the number itself.
Example:
Number 9 is a Neon number, because 9 is equal to sum of the digits of square of number (9x9 = 81 = 8+1 = 9).
Program to check Neon number in Java
import java.util.Scanner;
public class NeonNumber
{
public static void main(String[] args)
{
int n,square,sum=0;
//create object of scanner.
Scanner sc = new Scanner(System.in);
//you have to enter number here.
System.out.print("Enter the number: " );
n=sc.nextInt();
//calculate square.
square=n*n;
while(square>0)
{
sum=sum+square%10;
square=square/10;
}
//condition for checking sum is equal or not.
if(sum==n)
System.out.println("Its a Neon number.");
else
System.out.println("Its not a Neon number.");
}
}
Output
First run:
Enter the number: 9
Its a Neon number.
Second run:
Enter the number :6
Its not a Neon number.