输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

public static void main(String args[])throws IOException{ System.out.println("Please Input the String."); Scanner sc = new Scanner(System.in); String string =sc.next(); int other =0; int character =0; int blank =0; int number =0; System.out.println(string); System.out.println(other); for(int i =0;i=65&&string.charAt(i)<=122){ character++; } else if(string.charAt(i)>=48&&string.charAt(i)<=57){ number++; }else{ other++; } } System.out.println("字母有"+character+"个"); System.out.println("空格有"+blank+"个"); System.out.println("数字有"+number+"个"); System.out.println("其他字符有"+other+"个"); } }

你可能感兴趣的:(输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数)