/zifugeshu
package 字符个数; import java.util.Scanner; public class zifugeshu { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int num=0,eng=0,china=0; for(int i =0;i<s.length();i++){ if(s.charAt(i)>=‘0‘&&s.charAt(i)<=‘9‘){ num++; }else if((s.charAt(i)>=‘a‘&&s.charAt(i)<=‘z‘)||(s.charAt(i)>=‘A‘&&s.charAt(i)<=‘Z‘)){ eng++; }else if((19968 <= s.charAt(i) && s.charAt(i) <40623)) { china++; } } System.out.println("数字是:"+num); System.out.println("英文是:"+eng); System.out.println("中文是:"+china); } }
时间: 2024-11-08 01:38:48