java 找出100以内的素数

王朝学院·作者佚名  2009-11-13  
宽屏版  字体: |||超大  

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

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有