Java Program To Check Neon Number or Not
A neon number is a number where the sum of digits of square of
the number is equal to the number.
Example :
Given Number : 9
It is a Neon Number
Square of a Given Number : 9*9 = 81
Sum of Digit of a Square of a Given Number : 8+1 = 9
Since :
Sum of Digit of a Square of a Given Number is Equal To The Number (Given Number)
Example :
Given Number : 5
It is Not a Neon Number
Square of a Given Number : 5*5 = 25
Sum of Digit of a Square of a Given Number : 2+5 = 7
Since :
Sum of Digit of a Square of a Given Number is Not Equal To The Number (Given Number)
you can use the following algorithm:
- Read the input number.
- Square the input number and store it in a variable square.
- Initialize a variable sum to 0.
- While square is not equal to 0,perform the following steps:
- Get the last digit of square by using the modulo operator (%).
- Add the last digit to sum.
- Divide square by 10 to remove the last digit.
- Check if the sum is equal to the input number.
- If they are equal, the number is a Neon Number.
Otherwise, it is not. - Print the result.
In this algorithm, the input number is squared and the sum of the digits of the squared number is calculated. Then, the algorithm checks if the sum is equal to the input number. If they are equal, the number is considered a Neon Number.
Please note that this implementation assumes that the input number is a positive integer. You may need to add additional checks for negative numbers or other cases depending on your requirements.
Here is an example implementation in Java
Source Code
// Java Program To Check Neon Number or Not
import java.util.*;
public class NeonNumber
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int num , Square , Rd , sum = 0 ;
System.out.print("Enter a Number To Check : ");
num=in.nextInt();
Square = num * num ;
while ( Square!=0 )
{
Rd = Square % 10 ;
sum = sum + Rd ;
Square = Square / 10 ;
}
if( sum==num )
System.out.print("It is a Neon Number . ");
else
System.out.print("It is Not a Neon Number . ");
}
}
Output
Sample Input :
Enter a Number To Check : 9
Sample Output:
It is a Neon Number
Sample Input :
Enter a Number To Check : 5
Sample Output:
It is Not a Neon Number
Looping Related Programs
- Java Program to Check Prime Number or Not
- Java Program to Check Twin Prime Number or Not
- Java Program to Check Perfect Number or Not
- Java Program to Check Spy Number or Not
- Java Program to Check Neon Number or Not
- Java Program to Check Duck Number or Not
- Java Program to Check Niven or Harshad Number or Not
- Java Program to Check Palindrome Number or Not
- Java Program to Check Armstrong Number or Not
- Java Program to Check Strong (Krishnamurthy) Number or Not
- Java Program to Check Automorphic Number or Not
- Java Program to Check Happy Number Or Not