0% found this document useful (0 votes)
3 views4 pages

Numbers Program

The document contains a Java program that defines various mathematical functions to check for perfect numbers, spy numbers, neon numbers, palindromes, strong numbers, Armstrong numbers, and automorphic numbers. It includes methods for checking these properties within specified ranges and prints the results. The main method demonstrates the use of these functions with specific examples and ranges from 1 to 500 or 200.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Numbers Program

The document contains a Java program that defines various mathematical functions to check for perfect numbers, spy numbers, neon numbers, palindromes, strong numbers, Armstrong numbers, and automorphic numbers. It includes methods for checking these properties within specified ranges and prints the results. The main method demonstrates the use of these functions with specific examples and ranges from 1 to 500 or 200.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

05/01/2026, 13:05 Java Code

Java Code
1 public class MyClass {
2 public static void main(String args[]) {
3 int n =28;
4 [Link](PerfectNum(1,n,0));
5
6 int n1 =6;
7 [Link](isSpy(n1,0,1));
8
9 int n2 =9;
10 [Link](neon(n2,n2*n2,0));
11
12 int n4= 121;
13 [Link](isPalindrome(n4,n4,0));
14
15 int n5 = 145;
16 [Link](Strong(n5, n5,0,1));
17
18 int n6 = 153;
19 [Link](Armstrong(n6 , n6,0));
20
21 int n7 = 25;
22 [Link](Automorphic(n7 , n7*n7));
23
24 PerfectRange(1, 100);
25 [Link]();
26
27
28 SpyRange(1, 100);
29 [Link]();
30
31
32 NeonRange(1, 100);
33 [Link]();
34
35
36 PalindromeRange(1, 200);
37 [Link]();
38
39
40 StrongRange(1, 500);
41 [Link]();
42
43
44 ArmstrongRange(1, 500);
45 [Link]();
46
47
48 AutomorphicRange(1, 200);
49 [Link]();

[Link] 1/4
05/01/2026, 13:05 Java Code

50
51 }
52
53 public static boolean PerfectNum(int i,int n, int sum ){
54 if(i > n/2) return n ==sum;
55 if(n%i == 0) sum += i;
56 return PerfectNum(i+1,n,sum);
57
58 }
59
60 public static boolean isSpy(int n ,int sum ,int prod){
61 if(n == 0) return sum == prod;
62 sum += n%10;
63 prod *= n%10;
64
65 return isSpy(n/10 , sum , prod);
66 }
67
68 public static boolean neon(int n , int sq , int sum ){
69 if(sq == 0) return sum == n;
70 sum += sq%10;
71
72 return neon(n,sq/10,sum);
73 }
74
75 public static boolean isPalindrome(int n,int m, int rev){
76 if(n == 0) return m == rev;
77 rev = rev*10 + n%10;
78
79 return isPalindrome(n/10 , m ,rev);
80 }
81
82 public static boolean Strong(int n , int temp,int sum, int fact){
83 if(temp == 0) return sum == n;
84 int digit = temp%10;
85
86 fact =1;
87 for(int i=1;i<=digit; i++){
88 fact *= i;
89 }
90
91 return Strong(n , temp/10 ,sum+ fact ,1);
92 }
93
94 public static boolean Armstrong(int n,int temp,int sum){
95 if(temp == 0)return sum == n;
96 int digit = temp%10;
97 int digits = countDigits(n);
98
99 int power =1;
100 for(int i=1;i<=digits;i++){
101 power *= digit;

[Link] 2/4
05/01/2026, 13:05 Java Code

102 }
103
104 return Armstrong(n,temp/10,sum + power);
105 }
106
107 public static int countDigits(int n) {
108 if (n == 0) return 0;
109 return 1 + countDigits(n / 10);
110 }
111
112 public static boolean Automorphic(int n, int sq){
113 if(n == 0) return true;
114
115 if(n%10 != sq%10) return false;
116

117 return Automorphic(n/10, sq/10);


118 }
119
120
121 // for calling ranges
122
123 public static void PerfectRange(int start, int end) {
124 if (start > end) return;
125
126 if (PerfectNum(1, start, 0)) {
127 [Link](start + " ");
128 }
129
130 PerfectRange(start + 1, end);
131 }
132
133 public static void SpyRange(int start, int end) {
134 if (start > end) return;
135
136 if (isSpy(start, 0, 1)) {
137 [Link](start + " ");
138 }
139
140 SpyRange(start + 1, end);
141 }
142
143 public static void NeonRange(int start, int end) {
144 if (start > end) return;
145
146 if (neon(start, start * start, 0)) {
147 [Link](start + " ");
148 }
149
150 NeonRange(start + 1, end);
151 }
152
153 public static void PalindromeRange(int start, int end) {

[Link] 3/4
05/01/2026, 13:05 Java Code

154 if (start > end) return;


155
156 if (isPalindrome(start, start, 0)) {
157 [Link](start + " ");
158 }
159
160 PalindromeRange(start + 1, end);
161 }
162
163 public static void StrongRange(int start, int end) {
164 if (start > end) return;
165
166 if (Strong(start, start, 0, 1)) {
167 [Link](start + " ");
168 }
169
170 StrongRange(start + 1, end);
171 }
172
173 public static void ArmstrongRange(int start, int end) {
174 if (start > end) return;
175
176 if (Armstrong(start, start, 0)) {
177 [Link](start + " ");
178 }
179
180 ArmstrongRange(start + 1, end);
181 }
182
183 public static void AutomorphicRange(int start, int end) {
184 if (start > end) return;
185
186 if (Automorphic(start, start * start)) {
187 [Link](start + " ");
188 }
189
190 AutomorphicRange(start + 1, end);
191 }
192
193
194
195 }

[Link] 4/4

You might also like