题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        while (in.hasNextLine()) { 
            String str = in.nextLine();
            int letter=0;
            int blank=0;
            int number=0;
            int other=0;

            for(int i=0;i<str.length();i++){
                char ch = str.charAt(i);
                if(ch>='a'&& ch<='z'|| ch>='A'&&ch<='Z'){
                    letter++;
                }else if(ch==' '){
                    blank++;
                }else if(ch>='0'&& ch<='9'){
                    number++;
                }else{
                    other++;
                }
            }
            System.out.println(letter);
            System.out.println(blank);
            System.out.println(number);
            System.out.println(other);
        }
    }
}

全部评论

相关推荐

10-21 00:37
已编辑
门头沟学院 C++
小浪_Coding:你问别人,本来就是有求于人,别人肯定没有义务免费回答你丫, 有点流量每天私信可能都十几,几十条的,大家都有工作和自己的事情, 付费也是正常的, 就像你请别人搭把手, 总得给人家买瓶水喝吧
点赞 评论 收藏
分享
09-29 15:34
已编辑
北京航空航天大学 C++
做个有文化的流氓:结果是好的,过程不重要,而且你的offer太多了
软开人,秋招你打算投哪些...
点赞 评论 收藏
分享
🎓学历背景:双非土木硕👨‍💻意向职位:AI应用开发大佬们可以帮我看看简历吗,秋招至今0offer
秋招结束再玩瓦:今年科班都不好找哇……你可以试试交叉岗,比如制造业国企的一些开发算法,或者互联网的边缘岗,it技术支持,运维这些
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务