編寫一個程序:找出大於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);
}
}
在線驗證
http://ideone.com/pVj7iy
211