I'm having some trouble with my code. I'm trying to write a method which will output all prime numbers from 2-10,000. I'm still a beginner in java and I wasn't sure how to go about doing this, I know I would use a binary search method and loops to do this. I tried to follow examples that I was reading through in my textbook and online; this is what I came up with, however it is not working properly. I'm not sure if it's entirely correct. Any help or advice on how to go about doing this or fixing this would be appreciated.
public static void prime() {
int i; // variable for loop
for(i=2; i<=10000; i++)
{
int factors =0;
int j = 1;
while(j<=i)
{
if(i%j == 0)
{
factors++;
} //End if
j++;
}
if(factors == 2)
{
System.out.println(i);
} //End if
}// End for
} // End method prime