public class ZhiShu{
public static void main(String[] args){
java.util.Scanner s = new java.util.Scanner(System.in);
System.out.print("请输入正整数:");
int i = s.nextInt();
int m = zhiShu(i);
System.out.println("比" + i + "大的最小质数是:" + m);
}
// 输出比i大的最小的质数
public static int zhiShu(int i){
boolean b = true;
int m = 0;
for (m = i + 1 ;m > i ; m++ ){
for (int x = 2;x < m ;x++ ){
if (m % x == 0 ){
b = false;
break;
}else {
b = true;
}
}
if (b){
break;
}else {
continue;
}
}
return m;
}
}```
输出大于i的最小的一个质数
最新推荐文章于 2024-11-08 14:58:24 发布