-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.java
More file actions
31 lines (24 loc) · 784 Bytes
/
Copy pathPrimeNumber.java
File metadata and controls
31 lines (24 loc) · 784 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
package Question2;
import java.util.Scanner;
public class PrimeNumber {
public static void main(String[] args) {
System.out.println("Please input one number that you are think it is a prime number");
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
if (input <= 1) {
System.out.println(input + "is not the prime number");
return;
}
boolean isPrime = true;
for (int i = 2; i < input -1 ; i++) {
if(input % i == 0) {
isPrime = false;
}
}
if(isPrime) {
System.out.println(input + " is prime number");
} else {
System.out.println(input +" " + "is not the prime number");
}
}
}