Character 클래스의 메소드
// Character 클래스의 메소드를 사용하는 예제 프로그램
public class StringMethods
{
public static void main(String[] args)
{
String aText="This is a text string.";
int spaces=0;
int vowels=0;
int letters=0;
String bText=aText.toLowerCase();
for(int i=0; i<aText.length(); ++i)
{
char ch=bText.charAt(i);
if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
{
vowels++;
}
if(Character.isLetter(ch))
{
letters++;
}
if(Character.isWhitespace(ch))
{
spaces++;
}
}
System.out.println( "vowels : " + vowels + "\n" +
"consonants : " + (letters - vowels) +
"\n" + "spaces : " + spaces + "\n");
}
}
'Java > 강의' 카테고리의 다른 글
Random 클래스 (0) | 2011.02.21 |
---|---|
vector 클래스 (0) | 2011.02.16 |
StringTokenizer 클래스 (0) | 2011.02.16 |
StringBuffer 클래스 (0) | 2011.02.15 |
String 클래스의 메소드 (0) | 2011.02.14 |