package ppt10lang包; import java.util.Scanner; //1.输入一段字符串,判断该字符串中数字的个数和字母的个数 public class Lianxi1 { public static void main(String[] args) { System.out.println("请输入一段字符串"); Scanner input = new Scanner(System.in); String str = input.nextLine(); char[] ch = str.toCharArray(); int num = 0; int letter = 0; for(char c:ch){ if(Character.isDigit(c)){ num++; }else if(Character.isLetter(c)){ letter++; } } System.out.println("该字符串中数字的个数为"+num+",字母的个数为"+letter); } }