-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsNumberPrime.java
36 lines (31 loc) · 887 Bytes
/
IsNumberPrime.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
package Data_Structure_And_Algorithm;
import java.util.Scanner;
public class IsNumberPrime {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("How many numbers you want to check: ");
int t = scanner.nextInt();
scanner.nextLine();
int count = 1;
while(count <= t){
System.out.print("Enter the number: ");
int num = scanner.nextInt();
scanner.nextLine();
System.out.println(num+ " is " +isPrime(num));
count++;
}
}
static String isPrime(int num) {
if (num <= 1) {
return "Not Prime";
}
int c = 2;
while (c * c <= num) {
if (num % c == 0) {
return "Not Prime";
}
c++;
}
return "Prime";
}
}