인프런 커뮤니티 질문&답변
[1단원 12번] nextLine()을 쓰면 왜 오류가 날까요?
해결된 질문
작성
·
388
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()의 차이는 개행문자로 알고있는데..... 그게 이 문제에서 어떻게 영향을 끼치는건가요?ㅠㅠ





