forked from NaNaDi/Programming_Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
50 lines (30 loc) · 800 Bytes
/
Copy pathPrime.java
File metadata and controls
50 lines (30 loc) · 800 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
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
public class Prime {
public static int chkprime(int num){
int temp = 1;
int prime_flag = 0;
while(temp<=((double)num)/2){
temp++;
if((num%temp)==0){
prime_flag++;
System.out.println(num+" is divisible by "+temp);
}
}
return prime_flag;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//todo: write a method which tells you if a given number is a prime or not
Prime pr = new Prime();
while(true){
System.out.println("Enter the number: ");
int number = scan.nextInt();
int flag = pr.chkprime(number);
if(flag == 0){
System.out.println(number+" is a prime");
}
else
System.out.println(number+" is not a prime");
}
}
}