编写一个程序:找出大于200的最小的质数
请用while do...while等循环
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int n = 201;
while (true)
{
boolean b = true;
for (int i = 2; i < n / 2; i++)
{
if (n % i == 0) b = false;
}
if (b) break;
n++;
}
System.out.println(n);
}
}
211
public class Operation2 {
public static void main(String[] args) {
// 200以内的质数 只能被1和它本身整除
for(int i=3;i<200;i++){
int sum=0;
for(int j=2;j<i;j++){
if(i%j==0){
continue;
}
sum+=1;
}
if(sum==(i-2)){
System.out.println(i);
}
}
}
}