找出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( );
                }
            }
        }
    }
}

 

posted on 2022-10-10 15:13  三岁学JAVA  阅读(133)  评论(0)    收藏  举报