class CodeRunner{
public static void main(String[] args){
char[] hex = {'C', 'A', 'F', 'E'};
String[] binary = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
String result="";
for (int i=0; i<hex.length; i++) {
if (hex[i]>='0' && hex[i]<='9'){
result +=binary[hex[i]-'0'];
}//end of if
else {//'A'~'F' 사이이면
result +=binary[hex[i]-'A'+10];
}//end of else
}//end of i
System.out.println("hex: "+ new String(hex));
System.out.println("binary: "+ result);
}
}
array 기초예제 코드인데요
밑에서 두번째 줄에 System.out.println("hex: "+ new String(hex)); 이부분에서 String이 왜 new String으로 가져와야 하는건지 궁금합니다 char 형을 String으로 가져오기 때문에 형변환 치원에서 필요한 건가요?