找出1~100以内的所有素数,每8个换一行输出
public class excercise { public static void main(String[] args) { int count = 0; for (int i = 2; i <= 100; i++) { boolean shisushu = true; for (int j = 2; j < i ; j++) { if(i%j == 0){ shisushu = false; break; } } if(shisushu){ count++; System.out.print(" 第"+count+"个素数是"+i); if(count%8 == 0){ System.out.println( ); } } } } }
浙公网安备 33010602011771号