-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp34.java
More file actions
35 lines (32 loc) · 774 Bytes
/
Exp34.java
File metadata and controls
35 lines (32 loc) · 774 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 Exp34 {
public static boolean isPrime(int number) {
if (number <= 1) {
return false;
}
if (number == 2) {
return true;
}
if (number % 2 == 0) {
return false;
}
for (int i = 3; i * i <= number; i += 2) {
if (number % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 1000; i++) {
if (isPrime(i)) {
System.out.print(i + " ");
count++;
if (count % 10 == 0) {
System.out.println();
}
}
}
System.out.println("\n\nTotal: " +count);
}
}