package com.javabin.interface_; /** * Copyright (C), 2018-2021, Mr.Lin * Author: Mr.Lin * Date: 2021/11/20 2:05 * FileName: Homework05 * Description:判断一个字符有多少个a~z,A~Z,0~9 */ public class Homework05 { public static void main(String[] args) { String str="326afef a32faADF 22SA"; conStr(str); } public static void conStr(String str) { if (str == null) { System.out.println("输入的字符为空!"); return; } int strLen = str.length(); int numCont = 0; int lowerCont = 0; int upperCont = 0; int everCont = 0; for (int i = 0; i < strLen; i++) { if (str.charAt(i) >= '0' && str.charAt(i) <= '9') { numCont++; } else if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') { lowerCont++; } else if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') { upperCont++; }else { everCont++; } } System.out.printf("%s该字符一共有: %n %d个数字;%n %d个小写;%n %d个大写;%n %d个其他;",str,numCont,lowerCont,upperCont,everCont); } }