编写一个Java Application,由用户输入一个正整数,输出从2到这个数之间的所有质数。怎么写啊?
展开全部
package print;
public class PrimeNumber {
public static final int CHECK = 100;
public static void main(String[] args) {
for (int i = 2; i < CHECK; i++) {
int count = 0;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
count++;
}
}
if (count == 0) {
System.out.println(i);
}
}
}
}
public class PrimeNumber {
public static final int CHECK = 100;
public static void main(String[] args) {
for (int i = 2; i < CHECK; i++) {
int count = 0;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
count++;
}
}
if (count == 0) {
System.out.println(i);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询