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