java 找出100以内的素数
2009-11-12 20:59:54 来源:WEB开发网核心提示:view plaincopy to clipboardPRint?public class FindPrime { /** * @param args */public static void main(String[] args) { // TODO Auto-generated method stub int nu
view plaincopy to clipboardPRint?
public class FindPrime {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 100;
String s = "100以内的素数:";
for (int i = 1; i <= num; i++) {
int count = 0;
for (int j = 1; j <= (int) Math.sqrt(i); j++) {
if (i % j == 0)
count++;
}
if (count > 1)
s += "";
else
s += i + " ";
}
System.out.println(s);
}
//result
//100以内的素数:1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
}
public class FindPrime {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 100;
String s = "100以内的素数:";
for (int i = 1; i <= num; i++) {
int count = 0;
for (int j = 1; j <= (int) Math.sqrt(i); j++) {
if (i % j == 0)
count++;
}
if (count > 1)
s += "";
else
s += i + " ";
}
System.out.println(s);
}
//result
//100以内的素数:1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
}
[]
- ››JavaScript拖拽原理的实现
- ››javascript事件列表解说
- ››Javascript代码优化工具UglifyJS
- ››Java Bean属性值动态设置
- ››JavaScript Confirm 失效的解决办法
- ››JavaScript页面内拖拽原理分析
- ››javascript中select的常用操作
- ››javascript+css无刷新实现页面样式的更换
- ››Java Web Services:不使用客户端证书的WS-Securit...
- ››Java开发2.0: 使用Amazon SimpleDB实现云存储,第...
- ››Java异常处理及其应用
- ››Java中遍历大容量map的正确方法
更多精彩
赞助商链接