-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_13primerange.java
More file actions
31 lines (30 loc) · 866 Bytes
/
_13primerange.java
File metadata and controls
31 lines (30 loc) · 866 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
import java.util.*;
public class _13primerange {
public static boolean prime(int n){
if ( n == 2){
return true;
}
for ( int i = 2 ; i <= Math.sqrt(n) ; i++){ //Math.sqrt(n) will find sq. root only .
if (n%i==0){
return false;
}
}
return true;
}
public static void primeinrange(int n){
for (int i = 2 ; i<=n ; i++ ){
if ( prime(i) ){
System.out.print(i + " ");
}
}
System.out.println();
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number to check Prime or not : ");
int b = sc.nextInt();
primeinrange(b);
System.out.println( prime(b) );
sc.close();
}
}