-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
CheckNeonNumber.java
61 lines (47 loc) · 1.19 KB
/
CheckNeonNumber.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Java Program to Check If a Number is Neon number or not
class CheckNeonNumber {
// Method to check whether number is neon or not
// Boolean type
public static boolean checkNeon(int n)
{
// squaring the number to be checked
int square = n * n;
// Initializing current sum to 0
int sum = 0;
// If product is positive
while (square > 0) {
// Step 1: Find remainder
int r = square % 10;
// Add remainder to the current sum
sum += r;
// Drop last digit of the product
// and store the number
square = square / 10;
}
// Condition check
// Sum of digits of number obtained is
// equal to original number
if (sum == n)
// number is neon
return true;
else
// number is not neon
return false;
}
// Main driver method
public static void main(String[] args)
{
// Custom input
int n = 9;
// Calling above function to check custom number or
// if user entered number via Scanner class
if (checkNeon(n))
// Print number considered is neon
System.out.println("Given number " + n
+ " is Neon number");
else
// Print number considered is not neon
System.out.println("Given number " + n
+ " is not a Neon number");
}
}