首页 > 编程语言 > 详细

1.键盘录入5个字符串,组成一个数组 2.统计录入的字符串数组中的大写字母,小写字母,数字分别有多少个.

时间:2020-12-15 10:33:36      阅读:35      评论:0      收藏:0      [点我收藏+]

`public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串中的大写字母,小写字母,数字都可以");
String s = sc.next();
count(s);

}

public static void count(String s) {
    char[] chars = s.toCharArray();
    int da = 0;
    int xiao = 0;
    int shu = 0;
    for (int i = 0; i < chars.length; i++) {
        if (‘A‘ <= chars[i] && chars[i] <= ‘Z‘) {
            da++;
        } else if (‘a‘ <= chars[i] && chars[i] <= ‘z‘) {
            xiao++;
        } else if (‘0‘ <= chars[i] && ‘9‘ >= chars[i]) {
            shu++;
        }
    }
    System.out.println("大写字母数量:" + da);
    System.out.println("小写字母数量:" + xiao);
    System.out.println("数字数量:" + shu);

}

}`

1.键盘录入5个字符串,组成一个数组 2.统计录入的字符串数组中的大写字母,小写字母,数字分别有多少个.

原文:https://www.cnblogs.com/WangMengyi/p/14136825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!