-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.2.java
More file actions
16 lines (15 loc) · 740 Bytes
/
3.2.java
File metadata and controls
16 lines (15 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Main{
public static void main(String args[]) {
int maxValue = 50; // The maximum value to be checked.
// Check all values from 2 to maxValue:
for(int i = 2 ; i <= maxValue ; ++i) {
// Try dividing by all integers from 2 to square root of i:
for(int j = 2 ; j <= Math.sqrt(i) ; ++j) {
if(i%j == 0) // This is true if j divides exactly
continue OuterLoop; // so exit the loop.
}
// We only get here if we have a prime:
System.out.println(i); // so output the value.
}
}
}