-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprimeCheck.java
60 lines (41 loc) · 935 Bytes
/
primeCheck.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class primeCheck
{
public static int enter;
public static void main (String [] args)
{
enterData();
runPrime.primeRunner(enter);
}
public static void enterData()
{
Scanner input = new Scanner(System.in);
System.out.print("Enter your number ->");
enter = input.nextInt();
}
}
class runPrime
{
static boolean notPrime = false;
public static void primeRunner(int ent)
{
while (ent>2)
{
ent--;
checkNumber(ent);
if (notPrime == false)
System.out.println(ent);
notPrime= false;
}
}
//goes through each number less than entered number
public static void checkNumber(int ent)
{
for (int i = (ent -1); i>=2; i--)
{
if (ent % i == 0)
notPrime = true;
}
//loops remainer division, if not prime, sets bool not prime to true
}
}