-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeonNumberCheck.java
More file actions
28 lines (25 loc) · 841 Bytes
/
NeonNumberCheck.java
File metadata and controls
28 lines (25 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 39. Write a program to check if a given number is a neon number.
import java.util.Scanner;
public class NeonNumberCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
boolean isNeon = isNeonNumber(num);
if (isNeon) {
System.out.println(num + " is a neon number.");
} else {
System.out.println(num + " is not a neon number.");
}
scanner.close();
}
public static boolean isNeonNumber(int num) {
int square = num * num;
int sumOfDigits = 0;
while (square > 0) {
sumOfDigits += square % 10;
square /= 10;
}
return sumOfDigits == num;
}
}