JAVA/기초 프로그래밍
대문자 -> 소문자변환 프로그램/ ASCII
웨이칭
2020. 5. 26. 14:09
대문자로 입력 -> 소문자로 변환해서 출력 되도록하는 프로그램
단) toLowerCase사용하지 말고 구현
/*
ABCdE -> abcde
A -> 65, a-> 97 차이는 +32
*/
Scanner sc = new Scanner(System.in);
System.out.println("영문 문자열을 입력해 주세요");
String _str = sc.next();
String result = "";
// String upStr = str.toLowerCase();
// System.out.println("upStr = "+upStr);
//아스키코드로 변경 후 +32 하면 소문자로 바뀜
for (int i = 0; i < _str.length(); i++) {
char c = _str.charAt(i); //<=> indexOf
if ((int)c >=65 && (int)c <= 91) {
int n = (int)c + 32;
result = result + (char)n;
}else {
result += c;
}
}
System.out.println("원본 문자열= "+_str);
System.out.print("변환 문자열 = "+result);
힌트;
아스키코드로 변경 후 +32 하면 소문자로 바뀜