Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prime Program

 
Joe Grafton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic