-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
40 lines (30 loc) · 707 Bytes
/
Copy pathPrime.java
File metadata and controls
40 lines (30 loc) · 707 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
package javacodingexample;
import java.util.Scanner;
import java.lang.*;
public class Prime {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Please, enter a starting number :");
String val=sc.next();
int x = Integer.parseInt(val);
System.out.println("Please, enter a last number :");
val=sc.next();
int y=Integer.parseInt(val);
System.out.println("Printing the prime number from : " + x +" to " + y);
for(int i=x; i<=y; i++){
if(isPrime(i)){
System.out.println(i);
}
}
}
public static boolean isPrime(int i) {
for(int j=2;j<i;j++){
if(i % j == 0){
return false ;
}
else {
return true;
}
}
}
}