// 입력 번호를 얻은 다음 소수 일 경우 해결됩니까? //은스레드 "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");
}
}
}에서 입력을 가져옵니다. 또한 Scanner#nextInt
@throws InputMismatchException
* if the next token does not match the <i>Integer</i>
* regular expression, or is out of range