新闻正文

发一个求质数的简单的实现的方法

来源:JAVA天堂  JAVA学习者  2007-8-7 01:57:49 网友评论 0 条 字体:[ ] ~我要投稿!
我爱南开站 (Mon Apr 5 13:47:21 2004)
转信站: SJTU!netnews.sdu.edu.cn!news.happynet.org!NanKai
public class Primes {
public static void main(String args[]) {
int maxValue = 50; // The maximum value to be checked.
// Check all values from 2 to maxValue:
OuterLoop:
for(int i=2 ; i<=maxValue ; i++) {
// Try dividing by all integers from 2 to square root of i:
for(int j=2 ; j<=Math.sqrt(i) ; j++) {
if(i%j == 0) // This is true if j divides exactly
continue OuterLoop; // so exit the loop.
}
// We only get here if we have a prime:
System.out.println(i); // so output the value.
}
}
}
【 在 nanfangniao (nanfangniao) 的大作中提到: 】
:
:
: public class zhishu
: {
: public static void main(String [] args)
: {
:
: int big = 1000;
: for(int i = 3 ; i <= big; i ++ )
: {
: .................(以下省略)

被神仙抓去以后,第一天,他们打我,我没有说,第二天,他们
打我,我还是没有说,第三天,他们送来一个漂亮mm,我说了,
第四天,我还想说,可是他们把我砍了……



收藏到ViVi   收藏此页到365Key
上一篇: java beans的一个小问题!
下一篇: 发一个求质数的简单的实现的方法
用户名:新注册) 密码: 匿名评论 [所有评论]
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
本栏搜索
  • Google
   网站首页 -  网站地图 -  技术学习 -  网站投稿 -  帮助中心
Copyright 2003-2008 www.javah.net All Rights Reserved
2008 如果你喜欢本站 请收藏本站 并推荐给你的朋友一起分享