zoukankan      html  css  js  c++  java
  • 判断101-200之间的素数

     1 /*【程序2】
     2 题目:判断101-200之间有多少个素数,并输出所有素数。
     3 判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,
     4 则表明此数不是素数,反之是素数。 */
     5 
     6 public class SecondPrimeNumber {
     7     public static int count=0;
     8 public static void main(String[] args) {
     9     for(int i=101;i<200;i++) {
    10         boolean b=true;
    11         for(int j=2;j<Math.sqrt(i);j++) {
    12             if(i %j==0)
    13                 b=false;
    14         }
    15             
    16         if(b) {
    17             count++;
    18             System.out.print(i+" ");
    19         }
    20     }
    21     System.out.println("
    素数的个数"+count);
    22     
    23 }
    24 }
  • 相关阅读:
    关于C#登录三层
    SQL 语句关于分页的写法
    C# 如何去掉button按钮的边框线
    20151220
    继承
    对象的旅行
    多态
    封装
    OO大原则
    javascript
  • 原文地址:https://www.cnblogs.com/P201421420035/p/8664299.html
Copyright © 2011-2022 走看看