Java求100以内的素数

*因为1既不是质素也不是素数,所以从2开始*

下面给出了一种简单的方法:

public class ceshi{

  public static void main(String[] args){

    int j;

    for(int i=2; i <= 100; i++ ) {

      for( j = 2; j <= i; j++ ) {

        if( i % j == 0 ) {

          break;

        }

      }

      if( j >= i ) {

        System.out.println(i);

      }

    } 

  } 

}

原文地址:https://www.cnblogs.com/taosheng-yijiu/p/12970763.html