/*
输出1~100之间的所有质数
只能被1和本身整除的数 (即:从2开始到小于这个数本身结束的自然数中,没有能被这个数除尽的数存在)
*/
class TestZhiShu
{
public static void main(String[] args)
{
boolean flag=true;
long start=System.currentTimeMillis();//获取当前时间(ms)
for(int i=2; i<10000;i++){
for(int j=2; j<=Math.sqrt(i);j++){
if(i%j==0){
flag=false;
break;
}
}
if(flag==true)
System.out.println(i);
flag=true;
}
long end=System.currentTimeMillis();
System.out.println("程序执行时间为:"+(end-start)+"ms");
}
}本文出自 “第一天的课” 博客,请务必保留此出处http://5453607.blog.51cto.com/5443607/1530866
原文:http://5453607.blog.51cto.com/5443607/1530866