您的位置:首页 > 其它

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

2010-03-20 16:37 225 查看
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<string.length();i++){
System.out.println(i);
if(string.charAt(i)==32){
blank++;
}
else if(string.charAt(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+"个");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐