ナカザンドットネット

Android Developer's memo

練習問題2.7 その他のラップクラス

1. Characterクラスの静的メソッドの使い方を示すプログラムを作成しなさい。

class CharacterDemo{
    public static void main(String[] args){
	char c1 = '1';
	char c2 = 'A';
	char c3 = ' ';
	char c4 = 'a';

	System.out.println(c1 + " is digit? ->\t\t" 
			   + Character.isDigit(c1));

	System.out.println(c2 + " is letter? ->\t\t" 
			   + Character.isLetter(c2));

	System.out.println(c1 + " is letter or digit? ->" 
			   + Character.isLetterOrDigit(c1));

	System.out.println(c2 + " is lower case? ->\t" 
			   + Character.isLowerCase(c2));

	System.out.println(c2 + " is space? ->\t\t" 
			   + Character.isSpaceChar(c2));

	System.out.println(c2 + " is upper case? ->\t" 
			   + Character.isUpperCase(c2));

	System.out.println("["+c3+"]" + " is white space? ->\t" 
			   + Character.isWhitespace(c3));

	System.out.println(c2 + " is changed into " 
			   + Character.toLowerCase(c2));

	System.out.println(c4 + " is changed into " 
			   + Character.toUpperCase(c4));
    }
}