Neon Number Check in Java: Explanation & Practice
Check if sum of digits of square equals the number
Problem summary
A neon number is where the sum of digits of its square equals the number itself. Check if given number is neon.
Starter code
public class Main {
public static void main(String[] args) {
int number = 9; // Test case 1
// 9^2 = 81, 8+1 = 9 ✓
// Print: Is Neon: <true/false>
}
}Expected output and test cases
- 9² = 81, 8+1 = 9
Is Neon: true
- 1² = 1
Is Neon: true
- 5² = 25, 2+5 = 7 ≠ 5
Is Neon: false
Hints
- Square the number
- Calculate sum of digits of square
- Compare with original number
Related Core Java Basics exercises
Practice all Core Java Basics exercises · Run this idea in the Java compiler