a007.
判斷質數
| From: [114.36.36.21] |
發表日期
:
2011-11-16 17:36
import java.util.Scanner;
public class Main {
// private static int x;
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
boolean isPrime = true;
int number = cin.nextInt();
for (int i = 2; i < number; i++) {
if ((number % i == 0)) {
isPrime = false;
break;
}
}
if (isPrime==true) {
System.out.println("質數");
} else {
System.out.println("非質數");
}
}
}
}
執行逾時
請問如何解決?