입출력 이해하기
1. 다음 코드를 작성하여 실행 한 후, 콘솔에 12 34 65를 입력해서 출력을 확인해보세요.
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
System.out.println(input);
2. 위의 입 출력 동작을
System.in.read, System.out.write, System.out.print, System.out.flush와
변수를 자유롭게 이용해서 똑같이 구현해보세요.
즉, 4개의 함수를 이용해서
12 34 65 를 입력하면, (1)과 똑같이 출력이 나오게 구현하세요.
반복문은 사용하지 말구요!
✅첫번째 방법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
int input = System.in.read();
int input2 = System.in.read();
int input3 = System.in.read();
int input4 = System.in.read();
int input5 = System.in.read();
int input6 = System.in.read();
int input7 = System.in.read();
int input8 = System.in.read();
System.out.write(input);
System.out.write(input2);
System.out.write(input3);
System.out.write(input4);
System.out.write(input5);
System.out.write(input6);
System.out.write(input7);
System.out.write(input8);
System.out.flush();
|
cs |
✅결과

✅두번째 방법
1
2
3
4
5
6
7
8
9
|
System.out.write(System.in.read());//write는 byte코드를 입력받으면 시스템 기존값으로 변경해줌!
System.out.write(System.in.read());
System.out.write(System.in.read());
System.out.write(System.in.read());
System.out.write(System.in.read());
System.out.write(System.in.read());
System.out.write(System.in.read());
System.out.write(System.in.read());
System.out.flush();
|
cs |
✅결과
'IT > 뚝딱뚝딱' 카테고리의 다른 글
[JAVA] ✏️ 소인수분해 구현하기 (for문, while문) (2) | 2023.06.14 |
---|---|
[JAVA] ✏️ for문(반복문) 1~100사이의 홀수 개수 출력하기. (0) | 2023.06.14 |
[JAVA] ✏️ 조건문(if)으로 시험 성적 출력하기 (1) | 2023.06.14 |
이스케이프(고양이 만들기) (0) | 2023.06.09 |
출력 도구 (3) | 2023.06.08 |