-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmstrong.java
60 lines (53 loc) · 1.18 KB
/
Armstrong.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
package JAVACTOOOD;
import java.util.Scanner;
public class Armstrong {
public void displayAll(int n) {
System.out.println("The Numbers are : ");
for(int i = 0; i <= n; i++) {
int count = 0;
int sum = 0;
int temp = i;
while(temp > 0) {
temp = temp / 10;
count++;
}
if(count >= 2) {
temp = i;
while(temp > 0) {
int r = temp % 10;
sum = sum + (r*r*r);
}
if(sum == i) {
System.out.println(i);
}
}
else {
System.out.println(i);
}
}
}
public void checkArmstrong(int num) {
int sum = 0, temp = num;
while(temp > 0) {
int r = temp % 10;
temp = temp / 10;
sum = sum + (r * r * r);
}
if(sum == num) {
System.out.println("True");
}
else {
System.out.println("False");
}
}
public static void main(String[] argv) {
System.out.println("Enter the Value to Check : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println("Enter the number to print the values till a Number : ");
int display = sc.nextInt();
Armstrong sr = new Armstrong();
sr.checkArmstrong(num);
sr.displayAll(display);
}
}