1 1
2 2
3 3
4 4
... ...
33 33
34 34
I've looked all over the program and I can't seem to find the error.
import java.util.ArrayList;
public class PrimeNumber {
private int limit;
private ArrayList<Integer> primes = new ArrayList<Integer>();
public PrimeNumber (int limit) {
this.limit = limit;
}
public void generate() {
System.out.println("Index | Value");
for (int i = 1; i < limit; i++) {
boolean isPrime = false;
for (int j = 2; j <= limit; j++) {
if (!(i % j == 0)) {
isPrime = true;
}
}
if (isPrime) {
primes.add(i);
}
}
int ii = 1;
for (int i : primes) {
System.out.printf("%d%9d%n", ii++, i);
}
}
}
Also, for some reason Cloudfare or something said I posted content that triggered the security system?

New Topic/Question
Reply


MultiQuote



|