scanner

  • Scanner : ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์ด๋‚˜ ํŒŒ์ผ ๋“ฑ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ ๊ฐ’์„ ๋ฐ›์•„์˜ค๊ธฐ ์œ„ํ•œ ํด๋ž˜์Šค

package sec04.chap07;

import java.util.Scanner;

public class Ex01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String str1 = sc.next();
        String str2 = sc.next();
        String str3 = sc.nextLine();

        System.out.println("str1: " + str1);
        System.out.println("str2: " + str2);
        System.out.println("str3: " + str3);
    }
}

next : ์ŠคํŽ˜์ด์Šค๋ฅผ ๋น„๋กฏํ•œ ๊ณต๋ฐฑ ๋‹จ์œ„๋กœ ๋Š์–ด์„œ (ํ† ํฐ์œผ๋กœ) ๋ฌธ์ž์—ด์„ ๋ฐ›์Œ

nextLine : ์ค„๋ฐ”๊ฟˆ ๋‹จ์œ„๋กœ ๋Š์–ด์„œ ๋ฌธ์ž์—ด์„ ๋ฐ›์Œ

Last updated