-
Notifications
You must be signed in to change notification settings - Fork 0
/
primePrime.java
66 lines (62 loc) · 1.71 KB
/
primePrime.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
61
62
63
64
65
66
import java.lang.Runtime;
import java.lang.Exception;
public class primePrime{
public static void main(String[] args){
boolean isPrimeFactored = false;
for(int i = 1; i<2000; i++){
isPrimeFactored = checkPrimeFactors(i);
if(isPrimeFactored) {
System.out.print(i + ": " );
findFactors(i);
}
}
System.out.print("\033[H\033[2J");
System.out.flush();
clearConsole();
}
static boolean checkPrimeFactors(int n){
for(int i=2; i<=n; i++){
if(n%i == 0) {
boolean isPrime = true;
int valToBeChecked = i;
while(isPrime){
for(int k = 1; k<i; k++){
if(i%k == 0){
valToBeChecked = k;
continue;
}
}
break;
}
}
}
return true;
}
static void findFactors(int n){
for(int i = 2; i<n; i++){
if(n%i == 0) System.out.print(i + ", ");
}
System.out.println();
}
public final static void clearConsole()
{
try
{
final String os = System.getProperty("os.name");
if (os.contains("Windows"))
{
Runtime.getRuntime().exec("cls");
}
else
{
Runtime.getRuntime().exec("clear");
}
}
catch (final Exception e)
{
// Handle any exceptions.
System.out.println("uff");
e.printStackTrace();
}
}
}