I started writing (badly ;) ) a prime number finder in java code today...below is where I'm at just now, however, it returns "4" as a prime number (which it obviously isn't), however, I can't sort it for the correct "4" output without either breaking the program or 'cheating' by starting > 4. Anyone got any ideas? :)
Code:public class primefinder
{
public static void main(String[] args)
{
int count1 = 0;
int count2 = 0;
for(int number=2; number<50; number++)
{
count1 = 0;
for(int i=2; i<number/2; i++)
{
count2 = 0;
if(number%2 == 0.0)
{
count2++;
break;
}
else
{
if(number%i == 0.0)
count1++;
}
}
if(count1 == 0 && count2 == 0)
System.out.println(number+" is a prime number");
}
}
}