package com.fqs.demo001; import java.util.Scanner; public class Compare { public static void main(String[] args) { //键盘录入一个字符串,统计该字符串大写字母字符,小写字母字符,数字字符出现的次数 //比如ABCabc123 Scanner sc=new Scanner(System.in); System.out.println("请输入字符串"); String st=sc.next(); int len=st.length(); char[]c=new char[len]; byte[]b=new byte[len]; int c_1_num=0; int c_a_num=0; int c_A_num=0; for (int i = 0; i <len ; i++) { c[i]=st.charAt(i); } for (int i = 0; i <len ; i++) { b[i]= (byte) c[i]; System.out.println(b[i]); //判断大小写和数字 //97+26=123 中间是小写字母 65+26=91 中间是大写 48+10=58 是从0到9的数字 if(b[i]>=48&&b[i]<=58){ c_1_num++; }else if(b[i]>=65&&b[i]<=91){ c_A_num++; }else if(b[i]>=97&&b[i]<=123){ c_a_num++; } } System.out.println("包含数字的个数:"+c_1_num+";包含大写字母的个数:"+c_A_num+";包含小写字母的个数:"+c_a_num); } }
标签:小写字母,len,大写字母,int,num,&&,new,101 From: https://www.cnblogs.com/haha1988/p/17486267.html