//获取输入数字,然后解决它是否为素数? //从键盘线程“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");
}
}
}
//如果数量是素数它被打印,否则 //消息“不是素数”印刷得到输入。