next()2 [Java] next()와 nextLine() 차이점 Scanner 클래스의 String을 입력받는 메서드 next()와 nextLine() Scanner의 next()는 화이트스페이스를 기준으로 입력을 받는다. 화이트스페이스(whitespace)란? 의미없는 공백, 탭, 행 등 (' ', '\t', '\r', '\n' 등) next()와 nextLine() 차이점 next() '한 단어'를 기준으로 읽어들인다. = 공백을 기준으로 입력을 받는다. nextLine() '한 줄'을 기준으로 읽어들인다 = 개행을 기준으로 입력을 받는다. 2021. 11. 2. [백준 2558번 - java] A+B - 2 https://www.acmicpc.net/problem/2558 내 답안 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int A = s.nextInt(); int B = s.nextInt(); System.out.println(A+B); } } 1000번 문제(https://www.acmicpc.net/problem/1000)와는 다른 점 - 1000번 문제는 두 수를 한 줄에 입력받음 - 2558번 문제는 한 줄에 하나의 수를 입력받음 그러나 Scanner 클래스의 nextInt() 메서드는 공백(space)이나 개행(enter.. 2021. 11. 2. 이전 1 다음