Jop Tip

한글 영어 숫자 체크하기

omok 2010. 8. 11. 16:10

http://levin01.tistory.com/285

public class Test2 {

public static void main(String[] args) {
String str="한글12 this i8s english 입2니3다.";
int k=0;
int e=0;
int d=0;
int z=0;
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
//한글 ( 한글자 || 자음 , 모음 )
if( ( 0xAC00 <= c && c <= 0xD7A3 ) || ( 0x3131 <= c && c <= 0x318E ) ){
System.out.println("k"+c);
k++;
}else if( ( 0x61 <= c && c <= 0x7A ) || ( 0x41 <= c && c <= 0x5A ) ){
//영어
System.out.println("e:"+c);
e++;
}else if( 0x30 <= c && c <= 0x39 ){
//숫자
System.out.println("d"+c);
d++;
}else{
System.out.println("z"+c);
z=0;
}
}

System.out.println("-------결과--------");
System.out.println("한글:"+k);
System.out.println("영어:"+e);
System.out.println("숫자:"+d);
System.out.println("그외:"+z);
System.out.println("계:"+(k+e+d+z));
}
}

----------

k한
k글
d1
d2
z
e:t
e:h
e:i
e:s
z
e:i
d8
e:s
z
e:e
e:n
e:g
e:l
e:i
e:s
e:h
z
k입
d2
k니
d3
k다
z.
-------결과--------
한글:5
영어:13
숫자:5
그외:0
계:23