What is neon number:
A neon number is that where sum of digits of square of the number is equal to the number.
For example if the input number is 9, it's square is 9*9 = 81 and sum of the digits is 9. 9 is a neon number
Java Program to check neon number
Download eBook on BlueJ
import java.io.*;
class Neon
{
int n,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
System.out.println("Enter the number:");
n=Integer.parseInt(br.readLine());
sq=n*n;
while(sq>0)
{
sum=sum+sq%10;
sq=sq/10;
}
if(n==sum)
System.out.println(n+ " is a neon number");
else
System.out.println(n+ " is not a neon number");
}
public static void main(String args[])throws Exception
{
Neon ob=new Neon();
ob.showNeon();
}
}
BlueJ Program On Neon Numbers Between 1 And 500
import java.io.*;
class Neon
{
int i,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
for(i=1;i<=500;i++)
{
sum=0;
sq=i*i;
while(sq>=1)
{
sum=sum+sq%10;
sq=sq/10;
}
if(i==sum)
System.out.println(i+ " is a neon number");
}
}
public static void main(String args[])throws Exception
{
Neon ob=new Neon();
ob.showNeon();
}
}
Related Post: BlueJ Programs on Number
import java.io.*;
class Neon
{
int i,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
for(i=1;i<=500;i++)
{
sum=0;
sq=i*i;
while(sq>=1)
{
sum=sum+sq%10;
sq=sq/10;
}
if(i==sum)
System.out.println(i+ " is a neon number");
}
}
public static void main(String args[])throws Exception
{
Neon ob=new Neon();
ob.showNeon();
}
}
Related Post: BlueJ Programs on Number
plzz tell all neon numbers between 1to500
ReplyDeleteThe program will be posted very soon.
Deletepublic class Numbers {
Deletepublic static void main(String[] args) throws Exception {
for (int i = 1; i <= 5000; i++) {
if (isNeon(i)) {
System.out.println(i);
}
}
}
public static boolean isNeon (int number) {
int squareOfNumber = number * number;
int sum = 0;
while(squareOfNumber != 0) {
int lastNumber = squareOfNumber % 10;
squareOfNumber = squareOfNumber / 10;
sum = sum + lastNumber;
}
if (sum == number) {
return true;
}else {
return false;
}
}
}
Can u pls explain the logic of neon numbers? How to create the program?
ReplyDeleteTake the number which is to be checked for neon number and generate the square value of the number.
DeleteExtract each digit of the square value using a loop and store the sum of the digits. Now check whether the sum of the digits of the square value and the original number are equal. If equal then the number is a neon number and otherwise not.