I am working on a project that take in a starting number and a number of primes then outputs a table with each prime number after your starting number until it reaches your number of primes. I wrote a program to find the prime numbers but im having trouble getting the output to format in a table. I know i need to use nested for loops to build the table but im not sure how to go about starting that. Here is my code so far:
class Tester2{
public static void main(String[] args){
int number = 750000; //starting number
int nofn = 12; //number of primes to find
int primecount = 0;
while(primecount < nofn){
if(isPrime(number)){
primecount ++;
System.out.println(primecount + " " +number);
}
number++;
}
}
//determins if num is prime
private static boolean isPrime(int num){
int divisor = 2;
boolean itIsPrime;
while(num % divisor != 0){
divisor++;
}
if(divisor == num)
itIsPrime = true;
else
itIsPrime = false;
return itIsPrime;
}
}
Currently my code returns
1 750019
2 750037
3 750059
4 750077
5 750083
6 750097
7 750119
8 750121
9 750131
10 750133
11 750137
12 750151
and I am looking for it to return
Row #: 1--> 750019 750037 750059 750077 750083 750097 750119 750121 750131 750133
Row #: 2--> 750137 750151