-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjava profrem.txt
More file actions
29 lines (28 loc) · 904 Bytes
/
java profrem.txt
File metadata and controls
29 lines (28 loc) · 904 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
import java.util.Scanner;
public class Primenumber {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int num1, num2;
System.out.println("Please enter the first number:");
num1 = sc.nextInt();
System.out.println("Please enter the second number:");
num2 = sc.nextInt();
System.out.println("Prime numbers:");
for (int i = num1; i <= num2; i++) {
boolean isPrime = true;
if (i <= 1) {
isPrime = false;
} else {
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
}
if (isPrime) {
System.out.print(i + " ");
}
}
}
}