I have the following code for a primes program:
class Test2 {
public static void main(String[] args) {
System.out.println("Prime numbers inbetween 2-100: ");
boolean isComposite = false;
for (int i = 2; i <= 100; i++) {
if ((i % 2) == 0) {
continue;
}
for (int k = 3; k < i; k++) {
if ((i % k) == 0) {
isComposite = true;
break;
}
}
if (!isComposite) {
System.out.println(i);
isComposite = false;
}
}//End for
}//End main()
}//End class
My problem is, when I run that code I get the following output:
Prime numbers inbetween 2-100:
3
5
7
Such simple code, but I can't figure out whats wrong with it! Any help would be appreciated.
Also, what is the best algorithm for finds primes in Java?