int[] primers = new int[50]; int cnt; primers[0] = 2; cnt = 1; MAIN_LOOP: for(int x = 3;cnt < primers.length;x++) { for(int i = 0;i < cnt;++i) { if(x % primers[i] == 0) { continue MAIN_LOOP; } } primers[cnt++] = x; } for(int k:primers) { System.out.print(k + " "); }