File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Prime Program
 
Similar Threads
"write end dead" or "pipe" broken error
Help .. error in Inner Class
Finding the Nth Prime Number
Divisor or prime problem
Program that takes an int and returns an array of all the prime numbers smaller than that int