-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimos.java
More file actions
66 lines (65 loc) · 1.86 KB
/
Primos.java
File metadata and controls
66 lines (65 loc) · 1.86 KB
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
/**
* This class generates prime numbers
*
* @author (Yhoan Alejandro Guzman Garcia)
* @version (1.0)
*/
public class Primos {
void primos(int num) {
int[] primos = new int[num];
// int[] diferencia = new int[num];
int cont = 0;
primos[0] = 2;
int index = 1;
for (int i = 3; i <= num; i += 2) {
for (int j = 3; j <= Math.sqrt(i); j += 2) {
if ((i % j) == 0) {
cont++;
break;
}
}
if (cont == 0) {
primos[index] = i;
index++;
}
cont = 0;
}
System.out.println("Done");
}
public void imprimirDif(int[] diferencia, int index) {
for (int i = 0; i < index - 1; i++) {
//System.out.print(primos[i]+" | ");
if (diferencia[i] < 10) {
System.out.print(diferencia[i] + " | ");
} else {
System.out.print(diferencia[i] + " | ");
}
if ((i + 1) % 28 == 0) {
System.out.println();
}
}
}
public void imprimirPrim(int[] primos, int index) {
for (int i = 0; i < index; i++) {
if (primos[i] < 10) {
System.out.print(primos[i] + " | ");
} else {
System.out.print(primos[i] + " | ");
}
if ((i + 1) % 28 == 0) {
System.out.println();
}
}
}
public void imprimirCont(int[] contadores) {
for (int i = 0; i < contadores.length; i++) {
if (contadores[i] != 0) {
System.out.println("i: " + i + " -> " + contadores[i]);
}
}
}
public static void main(String[] args) {
Primos a = new Primos();
a.primos(100000000);
}
}