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

## Prime numbers

Hello Guys,

I am working on an assignment for find first 1000 prime numbers. Any help would be appreciated :D

I would like recursive method if possible.

Cheers.

2. ## Spoiler

Hello gapper

Here's a spoiler:
Java Code:
```public class Prime{
protected Vector<Integer> getFactors(int integer){
Vector<Integer> result = new Vector<Integer>();
for (int i = 1; i <= integer; i++)
if (integer &#37; i == 0) result.add(new Integer(i));
return result;
}
public Prime(int bound){
System.out.println("Prime numbers up to " + bound + ":");
for (int i = 2; i <= bound; i++){
if (getFactors(i).size() == 2) System.out.println(i);
}
}
}```
Use the constructor to run it
Java Code:
`new Prime(20);`
gives Output
Java Code:
```Prime numbers up to 20:
2
3
5
7
11
13
17
19```
This is a classical assignment. I could not resist. :D

3. Member
Join Date
Feb 2008
Posts
13
Rep Power
0
{
public static void main(String[] args)
{
int i,j;
i=1;
while(i<=1000)
{
j=2;
while(j<=i-1)
{
if(i&#37;j==0) break;
j++;
}
if(i==j)
System.out.print(i);
i++;
}
}
}

4. Member
Join Date
Feb 2008
Posts
3
Rep Power
0

## prime number....

{

public static void main(String[] args)
{

prime pr = new prime();
int number=Integer.parseInt(args[0]);
System.out.print("PRIME numbers are:");
for (int k = 0; k< primeNum.length; k++)
{
}
}
}

public class prime
{

{

int factCount=0;
int result[]=new int[4];
int k=0;

int j=0;

while(j<=primeno)
{
for(int i=2;i<=j;i++)
{
if(j%i==0)
{
factCount++;
}
}
if(factCount==1)
{
result[k]=j;

k++;
}
else
{

}
j++;
factCount=0;
}
return result;

}

}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•