1. Member Join Date
Jan 2011
Posts
17
Rep Power
0

## PrimeNumber

Hey
this is not my homework
I am studying my first test for final

here is the question

Consider the following unfinished class:
Java Code:
```public class MakePrimes {
int v[];
public MakePrimes () {
v = new int;
}
boolean isPrime (int n) {
???
}
public void fillV() {
???
}```
thank you  Reply With Quote

2. ## Ask a more specific question, and show some more work. What are you trying to do? Sieve of Eratosthenes? Just a regular approach? Try it and we will help you and possibly offer optimization ideas. For instance, did you know that when searching for a prime you will know whether it is prime by the time you reach the square root of n? Also, after testing 2, you can skip all even numbers from then on(2, 3, 5, 7, 9, etc.)  Reply With Quote

3. Member Join Date
Feb 2011
Posts
30
Rep Power
0

## I found this class using a quick Google search

Java Code:
```/*
This class writes out Prime numbers. A number is prime if it is
divisible by 1 and the number itself and no other number.
*/

{
// This method tests whether a given number is prime or not.
public static boolean isPrime ( int num )
{
boolean prime = true;
int limit = (int) Math.sqrt ( num );

for ( int i = 2; i <= limit; i++ )
{
if ( num % i == 0 )
{
prime = false;
break;
}
}

return prime;
}

public static void main ( String[] args )
{
// This loop writes out all the prime numbers less than 1000.
for ( int i = 2; i <= 1000; i++ )
{
if ( isPrime ( i ) )
System.out.println ( i );
}
}
}```  Reply With Quote

4. ## I understand the intentions here are good oomrichie, however; please don't spoonfeed. If he was pushed towards the right answer he would get a lot more help than just being given the answer. I know you found this on google and so could he have. Still, it doesn't help him learn much.  Reply With Quote

5. Member Join Date
Feb 2011
Posts
30
Rep Power
0

##   Reply With Quote