[Solved] Printing a triangle of prime numbers using for loop


These are two tasks: get the list of primes (or just something like nextPrime(int)) and get the triangle, both are very simple.

For the implementation of first, you may look at Next Prime number Java only working with certain numbers

For the implementation of second, just do something like:

for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < i; ++j) {
        nextPrime = ...
        System.out.print (nextPrime + " ");
    }
    System.out.println ();
}

solved Printing a triangle of prime numbers using for loop