如题,谢谢!!

解决方案 »

  1.   


    class Hello
    {
     public static void main(String args[])
     {
      int end=100;
      int begin=2;
      int i,j;
      for(i=begin;i<=100;i++)
      {
       for(j=2;j<=i/2;j++)
       {
        if(i%j==0)
         break;
       }
       if (j>i/2)
        System.out.println(""+i+"是素数");
          }
        }
    }
      

  2.   


    public static void main(String[] args) {
            int j;
            for(int i=0;i<=100;i++){
                j=2;
                while(i%j!=0)
                    j++;
                if(i==j){
                    System.out.println(i);            }
            }
        }
      

  3.   


    public class PrimeInteger{
      public static void main(String[] args){
        System.out.println(getPrime(1000));
      }
      
      public static ArrayList<Integer> getPrime(int max){
        boolean[] integers = new boolean[max + 1];
        int maxLength = (int)Math.sqrt(max);
        for(int i = 2; i <= maxLength; i++) {
          for(int j = 2 ; (j * i) <= max; j++) {
            integers[j*i] = true;
          }
        }
        ArrayList<Integer> result = new ArrayList<Integer>();
        for(int i = 1; i < integers.length; i++) {
          if(!integers[i]){
            result.add(i);
          }
        }
        return result;
      }
    }