判断101-200之间的素数

来源:互联网 发布:背包问题 动态规划java 编辑:程序博客网 时间:2024/06/13 08:29
package Test;
//判断101-200之间的素数
public class isPrime {

public static void main(String[] args) {
boolean b = false;
for (int i = 101; i < 201; i++) {

for (int j = 2; j <= i - 1; j++) {
if (i % j == 0) {
b = false;
break;
} else {
b = true;
}
}
if (b == true) {
System.out.print(i + " ");
}
}

}

}

结果:101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199