김찬진의 개발 블로그
23/02/02 [next(), nextLine()?] 본문
next()
공백문자 또는 개행문자 이전까지의 문자 또는 문자열을 반환
반환할 때 공백문자나 개행문자는 버퍼에서 제거
nextLine()
개행문자 이전까지의 문자 또는 문자열을 개행문자를 포함하여 반환
버퍼에 남아있는 문자가 없으므로 다음 입력 때 걱정할 필요없음
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// // Case1
// // a b
// // 1
// // = a\sb\n1
// String s1 = sc.next(); // a
// String s2 = sc.nextLine(); // \sb
// int i1 = sc.nextInt(); // 1
//
// System.out.println(s1);
// System.out.println(s2);
// System.out.println(i1);
// // Case2
// // a 1 b
// // = a\s1\sb\n
// String s1 = sc.next(); // a
// int i1 = sc.nextInt(); // 1 (int이니깐 \s 무시)
// String s2 = sc.nextLine(); // \sb
//
// System.out.println(s1);
// System.out.println(i1);
// System.out.println(s2);
// // Case3
// // a 1
// // = a\s1
// String s1 = sc.next(); // a
// int i2 = sc.nextInt(); // 1 (int이니깐 \s 무시)
// System.out.println(s1);
// System.out.println(i2);
// // CASE4
// // a b
// // 1
// // = a\sb\n1
// String s1 = sc.next(); // a
// String s2 = sc.nextLine();// \sb
// int i1 = sc.nextInt(); // 1 (int이니깐 \n 무시)
// System.out.println(s1);
// System.out.println(s2);
// System.out.println(i1);
// CASE4 SOLUTION
// a b 1
// = a\sb\s1
String s1 = sc.next(); // a
String s2 = sc.next();// b
int i1 = sc.nextInt(); // 1 (int이니깐 \n 무시)
System.out.println(s1);
System.out.println(s2);
System.out.println(i1);
}
}
'1일1배움 > Java' 카테고리의 다른 글
23/02/09 [인스턴스변수? 클래스변수? 지역변수?] (0) | 2023.02.09 |
---|---|
23/02/09 [내부클래스?] (0) | 2023.02.09 |
23/02/01 [replace()? replaceAll()? replaceFirst()?] (0) | 2023.02.01 |
23/02/01 [정규표현식(regex)?] (0) | 2023.02.01 |
23/01/31 [Character.isLetter()? Character.isDigit()?] (0) | 2023.01.31 |
Comments