isUpperCase, isLowerCase, isDigit

양혜정·2024년 1월 28일
0

Begin_java

목록 보기
25/71

isUpperCase()

  • 대문자인지 검사하기

isLowerCase()

  • 소문자인지 검사하기

isDigit()

  • 숫자인지 검사하기

=> boolean 타입으로 결과가 도출된다.


글자를 보고 해당글자가 몇개 있는지 확인하기

String word = "Abz3뭐a0#$T";
int upper_cnt = 0, lower_cnt=0, number_cnt =0, hangul_cnt=0, special_cnt=0;
	// 해당 개수들을 모두 0으로 초기화 시켜준다.
    
for(int i=0; i<word.length(); i++) {	// word.length() 는 글자의 길이를 뜻한다.
	char ch = word.charAt(i);	// chartAt(i)는 word의 인덱스 순서를 뜻하며,
    							// char 타입으로 변환된다.
    if(Character.isUpperCase(ch))	// 대문자인지 검사
    	upper_cnt ++;
    else if(Character.isLowerCase(ch))	// 소문자인지 검사
    	lower_cnt++;
    else if(Character.isDigit(ch))	// 숫자인지 검사
			number_cnt++;
	else if('가' <= ch && ch <= '힣')	// 한글인지 검사	// 하나라도 거짓이면 거짓!
			hangul_cnt++;
	else	// 특수문자
			special_cnt++;
}	// end of for--------------

정리

day05.f.For.quiz -> Main_quiz_1

0개의 댓글

관련 채용 정보