求出1-100之间所有的素数(只能被1和它本身整除),要求每5个换行输出。

publicclass chengxu2 {

       public static void main(String[] args) {

              int count = 4;

              System.out.print("2 3 5 7");

              for (int i = 10; i < 101; i++){

                     if ((i % 2 == 0) || (i % 3== 0) || (i % 5 == 0) || (i % 7 == 0)) {               //查找素数

                            continue;

                     } else {

                            System.out.print(i+"");

                            count++;

                            if (count%5 == 0) {                                                                               //计数

                                   System.out.println("");

                            }

                     } 

              }

       }

 }

你可能感兴趣的:(java笔记)