//獲取輸入數字,然後解決它是否爲素數? //從鍵盤線程「main」中的異常java.util.InputMismatchException
package basicjava;
import java.util.*;
public class Primes {
public static void main(String[] args) {
Scanner scanner = new Scanner("System.in");
System.out.println("Enter a Positive Integer Please ");
int userInput = scanner.nextInt();
int potentialFactor = 2;
while (userInput % potentialFactor != 0) {
potentialFactor++;
}
if (potentialFactor == userInput) {
System.out.println("the number is prime");
}
else {
System.out.println("the number is not prime");
}
}
}
//如果數量是素數它被打印,否則 //消息「不是素數」印刷得到輸入。