cs/java-spring-boot
[Zero-base] 1주차 과제 - 1번 과제 (FindName.java)
Lomo
2022. 1. 14. 20:16
반응형
https://gist.github.com/parkground/3b6b8485f7d1e29f617a3cdf55ef63a5
[Zero-base] 1주차 과제 - 1번 과제
[Zero-base] 1주차 과제 - 1번 과제. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
public class FindName {
//찾은 문자를 저장할 변수 선언 및 초기화
static int hex1 = 0;
static int hex2 = 0;
static int hex3 = 0;
public static void main(String[] args) {
//찾을 이름을 char에 각각 선언 및 초기화
char name1 = '박'; //0xbc15
char name2 = '지'; //0xc9c0
char name3 = '상'; //0xc0c1
//유니코드의 값의 범위 지정
char startValue = Character.MIN_VALUE; //'\u0000'
char endValue = Character.MAX_VALUE; //'\uffff'
//startValue부터 endValue까지 1씩 더하는 반복문
for (int i = startValue; i <= endValue; i++) {
//이름의 첫번쨰 자를 찾지 못한 경우
if (hex1 == 0) {
//첫번째 문자와 조건문의 문자와 일치하는 경우 그 값을 hex1에 저장
if ((i == (int)name1) && (name1 == (char)i)) {
hex1 = i;
}
}
//이름의 두번째 자를 찾지 못한 경우
if (hex2 == 0) {
//두번째 문자와 조건문의 문자와 일치하는 경우 그 값을 hex2에 저장
if ((i == (int)name2) && (name2 == (char)i)) {
hex2 = i;
}
}
//이름의 세번째 자를 찾지 못한 경우
if (hex3 == 0) {
//세번째 문자와 조건문의 문자와 일치하는 경우 그 값을 hex3에 저장
if ((i == (int)name3) && (name3 == (char)i)) {
hex3 = i;
}
}
//이름의 세 글자를 모두 찾은 경우 반복문 수행 종료
if ((hex1 != 0) && (hex2 != 0) && (hex3 != 0)) {
break;
}
}
//저장된 값들을 형식에 맞게 출력
System.out.printf("0x%X, 0x%X, 0x%X\n", hex1, hex2, hex3);
}
}
반응형