티스토리 뷰

반응형

⊙ 문제

 

OutputStream과 관련된 메서드를 이용해 0부터 9까지 연속된 숫자와 A부터 Z까지 알파벳 문자를 콘솔 뷰에 출력하는 프로그램을 작성하시오.

 

0의 ASCII 코드 값은 '48'이며, A의 ASCII 코드 값은 '65'이다. 콘솔은 표준 출력 장치이므로 System.out 객체를 OutputStream 타입의 변수에 대입해서 사용한다.

 


 

⊙ 문제 접근 과정

 

박스 안의 내용을 잘 보고 그대로 구현해보자.


 

⊙ 문제 풀이

 

import java.io.IOException;
import java.io.OutputStream;

public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream out=System.out;

        int num_ascii = 48;
        int alpha_ascii = 65;

        while (num_ascii<='9') {
            out.write(num_ascii++);
            System.out.print(" ");
        }

        System.out.println();

        while (alpha_ascii<='Z') {
            out.write(alpha_ascii++);
            System.out.print(" ");
        }

        out.flush();
    }
}

 


⊙ 결과

 


⊙ 마무리

 

 

NONE

 

좋아요는 로그인하지 않아도 누를 수 있습니다!

728x90
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함