This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Prime Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Prime Program" Watch "Prime Program" New topic
Author

Prime Program

Joe Grafton
Greenhorn

Joined: Feb 23, 2000
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

Joined: Feb 12, 2000
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prime Program
 
Similar Threads
Finding the Nth Prime Number
Divisor or prime problem
Help .. error in Inner Class
"write end dead" or "pipe" broken error
Program that takes an int and returns an array of all the prime numbers smaller than that int