forked from 14visheshjain/DataStructure-Algorithm-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprime.java
More file actions
40 lines (30 loc) · 623 Bytes
/
prime.java
File metadata and controls
40 lines (30 loc) · 623 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 lecture3;
import java.util.Scanner;
public class prime {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int min = s.nextInt();
int max = s.nextInt();
printprimes(min , max);
}
public static void printprimes(int n1 , int n2) {
while(n1<=n2) {
boolean b ;
b = isPrime(n1);
if(b)
System.out.println(n1);
n1++;}
}
public static boolean isPrime(int n) {
int i=2;
boolean check = true;
while(i<=n/2) {
if(n%i==0) {
check=false;
break;
}
i++;
}
return(check);
}
}