Java determines how many primes there are between 101 200 and outputs them

  • 2020-06-12 09:03:21
  • OfStack

Program analysis: The method of judging prime Numbers: divide 2 to sqrt(this number) with 1 number, if it can be divisible, it means that this number is not a prime number, and vice versa.

Program design:


public class exp2{
  public static void main(String args[]){
    int i=0;
    math mymath = new math();
    for(i=2;i<=200;i++)
      if(mymath.iszhishu(i)==true)
      System.out.println(i);
  }
}
class math
{
  public int f(int x)
  {
    if(x==1 || x==2)
      return 1;
    else
      return f(x-1)+f(x-2);
  }
  public boolean iszhishu(int x)
  {
    for(int i=2;i<=x/2;i++)
      if (x % 2==0 )
       return false;
    return true;
  }
}

This site has previously published primes between 1 and 100, so you can refer to 1 below


Related articles: