9
is a neon number, because the square of 9
is 81
and 8 + 1 = 9
.import java.util.Scanner;
public class NeonNumber {
public static void main(String[] args) {
// Get input from user
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number to check if it is a neon number: ");
int number = scanner.nextInt();
// Calculate square of number
int square = number * number;
// Calculate sum of digits of square
int sum = 0;
while (square != 0) {
int digit = square % 10;
sum += digit;
square /= 10;
}
// Check if sum of digits of square is equal to number
if (sum == number) {
System.out.println(number + " is a neon number");
} else {
System.out.println(number + " is not a neon number");
}
}
}
Enter a number to check if it is a neon number: 9
9 is a neon number
Enter a number to check if it is a neon number: 13
13 is not a neon number
Scanner
object. We then calculate the square of the number and the sum of its digits using a while
loop.