-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisPrime.java
More file actions
35 lines (32 loc) · 977 Bytes
/
Copy pathisPrime.java
File metadata and controls
35 lines (32 loc) · 977 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
public class isPrime {
public static void main(String[] args) {
int i, j, d = 2, step = 1, x = 100;
boolean isPrime = false;
System.out.print("Evens are:");
for (i = 2; i <= 100; i++) {
if (i%2 == 0) System.out.print(" " + i);
}
System.out.println(".");
System.out.print("Primes are:");
for (i = 2; i <= 100; i++) {
isPrime = true;
for (j = 2; j <= i/j; j++) {
if ((i % j) == 0) isPrime = false;
}
if (isPrime) System.out.print(" " + i);
}
System.out.println(".");
System.out.print("Unique prime factors of " + x + " are:");
while (x > 1) {
if (x % d == 0) {
System.out.print(" " + d);
x /= d;
while (x % d == 0) {
x /= d;
}
}
d += step;
step = 2;
}
}
}