-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_14_isprimenumber.java
More file actions
39 lines (31 loc) · 998 Bytes
/
Copy pathDay_14_isprimenumber.java
File metadata and controls
39 lines (31 loc) · 998 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
package Programing.Section5;
public class Day_14_isprimenumber {
public static void main(String[] args) {
int count = 0;
long starttime = System.nanoTime();
for(int i=250; i<360; i++) {
if(isPrime(i)) {
count++;
System.out.println("Number " + i + " is a prime number");
if(count == 10) {
System.out.println("Exiting for loop");
break;
}
}
}
long endtime = System.nanoTime();
System.out.println("our program took " +(endtime-starttime) + " nano seconds to execute");
}
public static boolean isPrime(int n) {
if(n == 1) {
return false;
}
for(int i=2; i <= n/2; i++) {
//System.out.println("Looping " +i);
if(n % i == 0) {
return false;
}
}
return true;
}
}