Neon Number Check in Java: Explanation & Practice

Check if a number is a Neon number

Problem summary

A Neon number equals the sum of digits of its square (e.g., 9² = 81, 8+1 = 9).

Starter code

public class Main {
    public static void main(String[] args) {
        int number = 9; // Test case 1
        
        // Check if Neon number
        // Print: Is Neon: <true/false>
    }
}

Expected output and test cases

  • 9² = 81, 8+1=9
    Is Neon: true
  • 1² = 1, 1=1
    Is Neon: true
  • 5² = 25, 2+5=7≠5
    Is Neon: false

Hints

  1. Calculate the square
  2. Sum all digits of the square
  3. Compare sum with original number

Related Control Flow exercises

Practice all Control Flow exercises · Run this idea in the Java compiler