티스토리 뷰

반응형

 

 

CHAPTER 01 | 연습문제 1번 문제 

다음 예제의 마지막 수행문인 write(b) 메소드를 write(byte[] data, int offset, int length) 메소드를 사용해서 같은 결과를 가지도록 수정하시오. 

public class DisplayCharacterBlock {

    public static void dcb() throws Exception {
        byte[] b = new byte[(172 - 31) * 2];
        int index = 0;

        for(int i = 32; i<127; i++){
            b[index] = (byte) i;
            if(i%8 == 7)
                b[index+1] = (byte)'\n';

            else
                b[index++] = (byte)'\t';
        }

        b[index++] = (byte)'\n';
        System.out.write(b);

    }
}

CHAPTER 01 | 연습문제 1번 문제 풀이 

public class DisplayCharacterBlock {

    public static void main(String[] args) throws Exception {
        byte[] b = new byte[(172 - 31) * 2];
        int index = 0;

        for(int i = 32; i<127; i++){
            b[index++] = (byte) i;
            if(i % 8 == 7)
                b[index++] = (byte)'\n';

            else
                b[index++] = (byte)'\t';
        }

        b[index++] = (byte)'\n';
        System.out.write(b, 0, index);

    }
}

 

 

결과 

 	!	"	#	$	%	&	'
(	)	*	+	,	-	.	/
0	1	2	3	4	5	6	7
8	9	:	;	<	=	>	?
@	A	B	C	D	E	F	G
H	I	J	K	L	M	N	O
P	Q	R	S	T	U	V	W
X	Y	Z	[	\	]	^	_
`	a	b	c	d	e	f	g
h	i	j	k	l	m	n	o
p	q	r	s	t	u	v	w
x	y	z	{	|	}	~
반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/06   »
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
글 보관함