forked from OOP-ADF/Task_1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.java
More file actions
41 lines (38 loc) · 949 Bytes
/
PrimeNumber.java
File metadata and controls
41 lines (38 loc) · 949 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
39
40
41
/*
* Alfian Rahman Aziz
* 1301150063
* IF 39-07
*/
package primenumber;
import java.util.Scanner;
/**
*
* @author Alfian R7
*/
public class PrimeNumber {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int n;
boolean isPrime = true;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number for check:");
//capture the input in an integer
int m = scan.nextInt();
for (int i = 2; i <= m / 2; i++) {
n = m % i;
if (n == 0) {
isPrime = false;
break;
}
}
//If isPrime is true then the number is prime else not
if (isPrime) {
System.out.println(m + " is Prime Number");
} else {
System.out.println(m + " is not Prime Number");
}
}
}