java100到200的质数
时间: 2023-09-10 20:15:11 浏览: 60
Java代码实现:
```
public class PrimeNumbers {
public static void main(String[] args) {
int start = 100;
int end = 200;
System.out.println("从" + start + "到" + end + "的质数有:");
for (int i = start; i <= end; i++) {
if (isPrime(i)) {
System.out.print(i + " ");
}
}
}
public static boolean isPrime(int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
```
输出结果为:
```
从100到200的质数有:
101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199
```
阅读全文