-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathu9.java
More file actions
40 lines (35 loc) · 883 Bytes
/
Copy pathu9.java
File metadata and controls
40 lines (35 loc) · 883 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
import java.util.*;
public class u9 {
static boolean isPrime(int j) {
if (j <= 1) {
return true;
}
if (j == 2) {
return true;
}
if (j % 2 == 0) {
return false;
}
int sqrtJ = (int) Math.sqrt(j);
for (int i = 3; i <= sqrtJ; i += 2) {
if (j % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
for (int i = 1; i <= 13; i++) {
if (!isPrime(i)) {
continue;
}
for (int j = 1; j <= i; j++) {
if (!isPrime(j)) {
continue;
}
System.out.print(j + " ");
}
System.out.println();
}
}
}