KnowledgeBoat Logo
|

Computer Applications

Define a class to accept a number and check whether the number is Neon or not. A number is said to be Neon if sum of the digits of the square of the number is equal to the number itself.

E.g.
Input: 9

Output:
9 * 9 = 81, 8 + 1 = 9
9 is Neon number.

Java

Java Iterative Stmts

55 Likes

Answer

import java.util.Scanner;

public class NeonNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number to check: ");
        int n = in.nextInt();
        int sq = n * n;
        int sqSum = 0;
        
        while (sq != 0) {
            int d = sq % 10;
            sqSum += d;
            sq /= 10;
        }
        
        if (sqSum == n)
            System.out.println("Neon Number");
        else
            System.out.println("Not a Neon Number");
    }
}

Output

BlueJ output of Define a class to accept a number and check whether the number is Neon or not. A number is said to be Neon if sum of the digits of the square of the number is equal to the number itself. E.g. Input: 9 Output: 9 * 9 = 81, 8 + 1 = 9 9 is Neon number.BlueJ output of Define a class to accept a number and check whether the number is Neon or not. A number is said to be Neon if sum of the digits of the square of the number is equal to the number itself. E.g. Input: 9 Output: 9 * 9 = 81, 8 + 1 = 9 9 is Neon number.

Answered By

25 Likes


Related Questions