I have this method.
The error says
primeList might not have been initialized.
I can't understand how this can be true. I feel like there's no way the variable wouldn't be initialized out of the for loops.
I can't figure out how to initialize a String
public void primesToANumber(long num) //finds all primes
{
String primeList ;
long pcount;
long limit = num;
JOptionPane.showMessageDialog(null,"Prime numbers between 1 and " + limit);
for(long i = 1; i < 100; i++)
{
boolean isPrime = true;
for(long j = 2; j < i ; j++)
{
if(i % j == 0)
{
isPrime = false;
break;
}
}
// print the number
if(isPrime)
{
primeList += i + ", ";
pcount++;
if(pcount % 12 ==0){
primeList += "\n";
}
}
}
JOptionPane.showMessageDialog(null, " " + primeList);
}