-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarclass8.java
40 lines (38 loc) · 1.06 KB
/
barclass8.java
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
40
import java.util.Scanner;
public class barclass8 {
public static void main( String args[] ) {
Scanner input = new Scanner(System.in);
int start, end, j;
System.out.println("What is your starting number: " );
start = input.nextInt();
System.out.println("What is your ending number: " );
end = input.nextInt();
for (j = start; j <= end; j++) {
boolean value = check_If_Prime(j);
if (value == true) {
System.out.println("prime number = " + j);
}
}
}
public static boolean check_If_Prime(int p) {
int i = 2;
boolean m = true;
if(p == 1 || p == 0) {
return false;
}
else {
while (i <= Math.sqrt(p) && m==true) {
if (p % i == 0) {
m = false;
}
else {
i++;
}
}
if (m == true)
return true;
else
return false;
}
}
}