-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrimeCheckerAPP.java
43 lines (40 loc) · 1.19 KB
/
PrimeCheckerAPP.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
36
37
38
39
40
41
42
43
//Name: Prabhav
//Period: 1A
import java.util.*;
public class PrimeCheckerAPP
{
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
int caller = 0;
int prime;
boolean isComposite = false;
while (caller != 2)
{
System.out.print("Press 1 to check if a number is prime, or press 2 to quit: ");
caller = console.nextInt();
System.out.print("");
if (caller == 2)
{
break;
}
System.out.print("Enter a number to enter in our algorithm: ");
prime = console.nextInt();
for (int factor = 1; (isComposite == false) && (factor < (prime - 1)); factor++)
{
if ((prime % factor) == 0)
{
isComposite = true;
}
}
if (isComposite == false)
{
System.out.println(prime+" is prime.");
}
else if (isComposite == true)
{
System.out.println(prime+" is composite.");
}
}
}
}