ADVERTISEMENT
ADVERTISEMENT

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.
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.