Yeah, so I was trying to make the computer list 100 prime numbers. But when I execute this, it only shows one: 3. (No, I do not want 2.)
Could someone please help try to make this print 100 prime numbers instead of just one? I'm not sure if it has something to do with the break statement, but it shouldn't cancel all loops, just the one that it is encased in.
Thanks in advance!
public class primenumbers { public static void main (String[]args){ int prime = 0; int repeater = 1; int number = 3; for (repeater = 1; repeater < 100; repeater++)/*repeat 100 times*/{ int divisor = 2; for(divisor = 2; divisor < number; divisor++ ){ if (number % divisor == 0){ prime = 0; break; } else{ prime = 1; } } if (prime==1){ System.out.println(number); number++; } }/*end for loop here*/ }}
Offline
this goes in advanced topics
yeah that makes no sense
but a couple of my flash threads got moved there
Offline