-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestions.java
More file actions
44 lines (38 loc) · 975 Bytes
/
Questions.java
File metadata and controls
44 lines (38 loc) · 975 Bytes
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
import java.util.Scanner;
public class Questions {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// int n = in.nextInt();
// boolean ans = isPrime(n);
// System.out.println(ans);
for (int i = 100; i < 1000; i++) {
if (isArmstrong(i)) {
System.out.print(i + " ");
}
}
}
// print all the 3 digits armstrong numbers
static boolean isArmstrong(int n) {
int original = n;
int sum = 0;
while (n > 0) {
int rem = n % 10;
n = n / 10;
sum = sum + rem*rem*rem;
}
return sum == original;
}
static boolean isPrime(int n) {
if (n <= 1) {
return false;
}
int c = 2;
while (c * c <= n) {
if (n % c == 0) {
return false;
}
c++;
}
return c * c > n;
}
}