Finding prime numbers
807607Oct 25 2006 — edited Oct 25 2006Hello,
I am currently taking an intro to java class and i was looking for help on the following problem.
I need to find all the prime numbers before N than display them along with how many prime numbers there are.
I cant put a counter in the loop since that will be equal to i and anything i put in the method will be reset. I have tried a few diffrent things yet no result
Any help that could point me in the right direction would be great.
Thank you
Here is my code so far. This will get all the prime number before the value N but i need to come up with a way of finding out how many prime numbers are before N.
import java.util.*;
public class Prime {
public static void Primes(int x){
if ((x%2)==0 && x!= 2){
System.out.print("");
}
else if((x%3)==0 && x != 3){
System.out.print("");
}
else if ((x%5)==0 && x != 5){
System.out.print("");
}
else{
System.out.print(+ x + " ");
}
}
public static void main(String [] args){
int repeatseq;
int num = 0;
Scanner value = new Scanner(System.in);
System.out.println("I want all the prime numbers before ");
repeatseq = value.nextInt();
for (int i = 0; i < repeatseq; i++){
Primes(i);
}
}
}