nextLine
을 활용하여 split
을 사용해 String[]
array 구조로 변환 및 저장array
변환 시 문장구조
이기에 정수변환 필요
Integer.parseInt(index)
> index
에 변환하고 싶은 값 투입class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.printf("""
"4 5" 똑같이 입력하세요.
""");
String input = sc.nextLine();
String[] inputArray = input.split(" ");
int n1 = Integer.parseInt(inputArray[0]); // inputArray[0] String 이므로 정수 변환
int n2 = Integer.parseInt(inputArray[1]);
System.out.printf("출력 : %d\n",n1+n2);
sc.close(); //scanner 종료
}
}