package ex18;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Buff02 {
public static void main(String[] args) {
InputStream in = System.in;
InputStreamReader rd = new InputStreamReader(in);
char[] buf = new char[4]; //길이가 4인 char[] buf 배열을 선언
try {
//rd.read(buf)로 4글자를 읽어 배열에 저장한다.
//입력이 4글자 미만이면 남은 배열 요소는 기본값 null로 채워진다.
rd.read(buf);
System.out.println(buf[0]);
System.out.println(buf[1]);
System.out.println(buf[2]);
System.out.println(buf[3]);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}


Share article