-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrough.java
More file actions
52 lines (44 loc) · 1.17 KB
/
rough.java
File metadata and controls
52 lines (44 loc) · 1.17 KB
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
import java.util.*;
public class rough {
public static boolean isprime(int n) {
if (n <= 1)
return false;
else {
for (int j = 2; j <= n / 2; j++) {
if (n % j == 0) {
return false;
}
return true;
}
}
return true;
}
public static boolean armstrong(int n) {
int number;
number = n;
int count = 0;
int sum = 0;
while (number != 0) {
number /= 10;
count++;
}
number = n;
while (number != 0) {
int rem = number % 10;
sum += (Math.pow(rem, count));
number /= 10;
}
return (n == sum);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number for range");
int num = sc.nextInt();
for (int i = 0; i < num; i++) {
if (isprime(i))
System.out.println(i);
else
System.out.println(armstrong(i));
}
}
}