package com.book.lite;import sun.lwawt.macosx.CSystemTray;import java.util.Scanner;/*** @author zhangyu* @date 2021年08月16日 10:50 下午* Character类的方法* 1.判断是否小写:isLowerCase()* 2.判断是否大写:isUpperCase()* 3.判断是不是数字:isDigit()** 4.将字符转成大写:toUpperCase()* 5.将字符转成小写:toLowerCase()* 6.判断一个字符串中有多少个:大写字母,小写字母,数字,其他字符*/
public class CharacterDemo {public static void main(String[] args) {System.out.println(methon_1('a'));System.out.println(methon_2('b'));System.out.println(methon_3('3'));System.out.println(methon_4('d'));System.out.println(methon_5('E'));/** 从键盘获取字符串*/Scanner sc = new Scanner(System.in);System.out.print("请输入字符串:");String s = sc.nextLine();methon_6(s);}public static boolean methon_1(char A){boolean a = Character.isLowerCase(A);return a ;}public static boolean methon_2(char B){boolean b = Character.isUpperCase(B);return b;}public static boolean methon_3(char C){boolean c = Character.isDigit(C);return c;}public static char methon_4(char D){char d = Character.toUpperCase(D);return d;}public static char methon_5(char E){char e = Character.toLowerCase(E);return e;}public static void methon_6(String s){int upper = 0;int lower = 0;int digit = 0;int other = 0;char[] ch = s.toCharArray();for (int x =0; x < ch.length ; x++){if (Character.isUpperCase(ch[x])){upper +=1;}else if (Character.isLowerCase(ch[x])) {lower += 1;}else if (Character.isDigit(ch[x])){digit +=1;}else {other +=1;}}System.out.println("大写字母有:"+upper);System.out.println("小写字母有:"+lower);System.out.println("数字有:"+digit);System.out.println("其他字符有:"+other);}
}