题解 | #统计字符#

统计字符

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);
        String  s=in.nextLine();
        int res_letter=0,res_space=0,res_dig=0,res_other=0;
        int len=s.length();
        char c;
        for(int i=0;i<len;i++){
            c=s.charAt(i);
            if(Character.isLetter(c))res_letter++;
            else if(c==' ')res_space++;
            else if(Character.isDigit(c))res_dig++;
            else res_other++;
        }
        System.out.println(res_letter);
        System.out.println(res_space);
        System.out.println(res_dig);
        System.out.println(res_other);
    }
}

全部评论

相关推荐

08-14 11:30
门头沟学院 Java
失去了成为米孝子的机会
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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