From 63eb39b2f38a831d92497f724b658f010e71997a Mon Sep 17 00:00:00 2001 From: Sumanth Desai Date: Thu, 19 Feb 2026 15:15:20 +0530 Subject: [PATCH] Add NeonNumber algorithm in maths package --- .../com/thealgorithms/maths/NeonNumber.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/com/thealgorithms/maths/NeonNumber.java diff --git a/src/main/java/com/thealgorithms/maths/NeonNumber.java b/src/main/java/com/thealgorithms/maths/NeonNumber.java new file mode 100644 index 000000000000..aa09817e6b27 --- /dev/null +++ b/src/main/java/com/thealgorithms/maths/NeonNumber.java @@ -0,0 +1,39 @@ +package com.thealgorithms.maths; + +/** + * This class checks whether a number is a Neon Number. + * A Neon number is a number where the sum of digits of + * its square is equal to the number itself. + * + * Example: + * 9^2 = 81 → 8 + 1 = 9 (Neon Number) + */ +public final class NeonNumber { + + private NeonNumber() { + // Prevent instantiation + } + + /** + * Checks if a number is a Neon Number. + * + * @param number the input number + * @return true if the number is a Neon Number, otherwise false + * @throws IllegalArgumentException if the number is negative + */ + public static boolean isNeon(int number) { + if (number < 0) { + throw new IllegalArgumentException("Number must be non-negative"); + } + + int square = number * number; + int sum = 0; + + while (square > 0) { + sum += square % 10; + square /= 10; + } + + return sum == number; + } +}