Sunday, April 28, 2024

Program To Check Neon number Using BlueJ

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 PostBlueJ Programs on Number



5 comments:

  1. plzz tell all neon numbers between 1to500

    ReplyDelete
    Replies
    1. The program will be posted very soon.

      Delete
    2. public class Numbers {

      public 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;
      }
      }
      }

      Delete
  2. Can u pls explain the logic of neon numbers? How to create the program?

    ReplyDelete
    Replies
    1. Take the number which is to be checked for neon number and generate the square value of the number.
      Extract 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.

      Delete

Subscribe via email

Enter your email address:

Delivered by FeedBurner