홈>
학교 프로젝트를하고 있는데, 코드에서 오류가 발생했습니다 : "main"스레드 예외 java.util.InputMismatchException 구분 기호 입력 문을 두 번 사용하려고 할 때.
하나의 입력 행만으로 시도했지만 작동하지만 다른 행을 추가하면 오류가 발생합니다.
Scanner input=new Scanner(System.in);
input.useDelimiter("##");
System.out.println("The delimiter is \'##\'");
System.out.print("Enter the name of product 1, product 2, and product 3: ");
String prod1 = input.next();
String prod2 = input.next();
String prod3 = input.next();
System.out.print("Enter the quantity of product 1, product 2, and product 3: ");
int quan1 = input.nextInt();
int quan2 = input.nextInt();
int quan3 = input.nextInt();
System.out.println(prod1+" "+prod2+" "+prod3);
System.out.println(quan1+" "+quan2+" "+quan3);
예상 결과는 내가 입력하면 생선 ## 바나나 ## 아이스크림 ### 과 3 ## 4 ## 5 ## 그런 다음 인쇄 생선 바나나 아이스크림 3 4 5
-
답변 # 1
-
답변 # 2
다음 입력을 시도하십시오. : 와이즈 비즈
개행도 읽을 수 있다고 생각하므로 첫 번째 nextInt가 실패합니다. 아마도 당신은 또한
fish##banana##ice cream##3##4##5##
를 사용하고 싶어 ##?에서 문자열을 분할 하시겠습니까? -
답변 # 3
맞춤식 구분 기호를 사용하는 이유는 무엇입니까? 새 줄로 구분하여 간단히 입력 할 수 있습니다.
input.nextLine()
Scanner input=new Scanner(System.in); System.out.println("Press enter key after every input"); System.out.print("Enter the name of product 1, product 2, and product 3: "); String prod1 = input.nextLine(); String prod2 = input.nextLine(); String prod3 = input.nextLine(); System.out.print("Enter the quantity of product 1, product 2, and product 3: "); int quan1 = input.nextInt(); input.nextLine(); int quan2 = input.nextInt(); input.nextLine(); int quan3 = input.nextInt(); input.nextLine(); System.out.println(prod1+" "+prod2+" "+prod3); System.out.println(quan1+" "+quan2+" "+quan3);
관련 자료
- 스레드"main"에서 예외 해결 javautilInputMismatchException
- python - 에 의해 시작된 스레드에서 처리되지 않은 예외
- python - 에 의해 시작된 스레드에서 처리되지 않은 예외
- hibernate - 스레드 "HikariPool-3 연결 클로저"의 예외
- 스레드"main"javalangillegalstateexception의 예외 - 스트림이 이미 작동되었거나 닫혔습니다
- c# - 스레드에서 예외를 잡는 지 어떻게 확인할 수 있습니까?
- scala - 스레드"main"javalangnoclassdeffounderror 예외 - org/rogach/scallop/scallopconf
- c# - WhenAll 메서드를 사용하는 스레드 간 예외
- spring tool suite의"thread"main"javalangnoclassdeffounderror 수정 방법 - org/springframework/core/io/support/springf
- multithreading - 예외 처리 방법을 사용하여 스레드를 종료하는 방법 - 파이썬
- java - 오류 - "javafx 응용 프로그램 스레드"스레드 예외
- apache poi - 스레드 "main"의 예외 javalangillegalargumentexception - 허용 범위 (01048575)를 벗어난 잘못된 행 번호 (-1)
- tiles - 스레드"thread-0"의 예외 javalangarrayindexoutofboundsexception - 5
- kafka - = "main"스레드 예외 orgapachesparksqlstreamingstreamingqueryexception : 연결에 대한 항목이 없습니다
- 스레드"main"javaioEOFException에서 예외를 수정하는 방법? (자바 소켓) [중복]
- 오류가 발생했습니다 스레드 "main"에서 예외가 발생했습니다 java 아래의 전체 오류
- javafx - 스레드"Thread-0"의 예외 javalangreflectInaccessibleObjectException
- "javafx 응용 프로그램 스레드"스레드 예외 comamazonawsservicess3modelamazons3exception - 액세스 거부
- 스레드"main"javalangnosuchmethoderror 예외 - scalapredef $longarrayops ([j) [j
- android - 문자열에서 HTML을로드 할 때 TWebBrowser에서 스레드 예외가 발생합니다
이 예외는 검색된 토큰이 예상 유형의 패턴과 일치하지 않거나 검색된 토큰이 범위를 벗어 났음을 표시하기 위해 Scanner 클래스의 인스턴스에서 발생합니다.