-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime.text
More file actions
41 lines (36 loc) · 948 Bytes
/
prime.text
File metadata and controls
41 lines (36 loc) · 948 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
/*A prime is a natural number greater than 1
that has no positive divisors other than 1 and itself.
Given a number,n,determine and print whether it's prime or not .*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
int n;
Scanner scn = new Scanner(System.in);
n = scn.nextInt();
for(int i=0; i<n; i++)
{
String ans = "Prime";
int x = scn.nextInt();
if(x==1)
{
ans = "Not prime";
}
else
{
for(int j=2; j<=x/2; j++)
{
if(x%j == 0)
{
ans = "Not prime";
break;
}
}
}
System.out.println(ans);
}
}
}