-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample5.java
More file actions
29 lines (24 loc) · 640 Bytes
/
Example5.java
File metadata and controls
29 lines (24 loc) · 640 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
package whileGita;
public class Example5 {
public static void main(String[] args) {
// System.out.println((int) Math.sqrt(997));
tubNumber(1000);
}
// 2 3 5 7 11 13 17 19 23 29 ...
public static void tubNumber(int n) {
for (int i = 2; i <= n; i++) {
if (tub(i)) System.out.print(i + " ");
}
}
// n
// 1 2 3 4 5 ... sqrt(n)
public static boolean tub(int number) {
int i = 2;
while (i < Math.sqrt(number)) {
if (number % i == 0)
return false; // tub emas
i++;
}
return true; // tub
}
}