This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Prime Program

Joe Grafton
Greenhorn
Posts: 5
Hello,
I am a beginner at this programming stuff but for my first class, the current assignment is to work with arrays, arraylists, etc. I am trying to do the classic Prime program and I would like to know if anyone out there can give me a hand. I don't even have to write the isPrime class. It supposedly is already givven to me. All I have to do is create an array and have the first 5 primes print out. I have written the for loop to place the ints into the array, but I can't seem to get the isPrime instance method to work. If anyone is out there, please let me know if you think you can help. Thanks a lot!!!
Joe

Eric Edwards
Ranch Hand
Posts: 60
Originally posted by Joe Grafton:
Hello,
I am a beginner at this programming stuff but for my first class, the current assignment is to work with arrays, arraylists, etc. I am trying to do the classic Prime program and I would like to know if anyone out there can give me a hand. I don't even have to write the isPrime class. It supposedly is already givven to me. All I have to do is create an array and have the first 5 primes print out. I have written the for loop to place the ints into the array, but I can't seem to get the isPrime instance method to work. If anyone is out there, please let me know if you think you can help. Thanks a lot!!!
Joe

int[] primes = new int[5];
int numPrimes = 0;
// pNum: the number that might be prime
int pNum = 2;
while (numPrimes < 6)
{
if (isPrime(pNum))
{
primes[numPrimes] = pNum;
numPrimes++;
}
pNum++;
}
This is part of the code for your program. Hope this helps.