//Character方法大小写转换
public class test25 {public static void main(String[] args) {char ch = 'A';//使用构造方法Character obj1 = new Character('中');//使用静态方法Character obj2 = Character.valueOf(ch);char[] arr = {'5', 'A', 'a', 'C', 'D', 'U', '5', '9',' ','J','9'};//countChar(arr);//大小写转换lowertoupper(arr);//输出整个数组for(char e:arr){System.out.println(e);}test25 uni=new test25();//判断是否为unicode的值System.out.println(uni.idDefine(65));}public Boolean idDefine(int ch){return Character.isDefined(ch);}//判断是否为unicode的值public static void lowertoupper(char[] chs){for(int i=0;i<chs.length;i++){if(Character.isLowerCase(chs[i])){chs[i]=(char)(((int)chs[i])-32);}else if(Character.isUpperCase(chs[i])){chs[i]=(char)(((int)chs[i])+32);}}}public static void countChar(char[] chs) {int letter = 0;//字母数量int upper = 0;//大写字母int lower = 0;//小写字母int sum = 0;//数字数量int space = 0;//空格数量for(int i=0;i<chs.length;i++){if(Character.isLetter(chs[i])){letter++;if(Character.isUpperCase(chs[i])){upper++;}else{lower++;}}else if(Character.isDigit(chs[i])){sum++;}else if(Character.isWhitespace(chs[i])){space++;}}System.out.println("字母"+letter);//字母System.out.println("大写字母"+upper);//大写字母System.out.println("小写字母"+lower);//小写字母System.out.println("数字"+sum);//数字System.out.println("空格"+space);//空格}
}
运行结果