-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
해결됨
[1단원 12번] nextLine()을 쓰면 왜 오류가 날까요?
23.01.04 18:15 작성 조회수 253
0
main메소드에서 입력을 nextLine을 이용해서 받으려고 했습니다
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int k = sc.nextInt();
String input = sc.nextLine();
Main T = new Main();
System.out.print(T.solution(k,input));
return ;
}
그런데 k 입력후 input을 입력 받기도 전에 다음오류가 뜨네요
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 7
next()와 nextLine()의 차이는 개행문자로 알고있는데..... 그게 이 문제에서 어떻게 영향을 끼치는건가요?ㅠㅠ
답변을 작성해보세요.
0
답변 1