题解 | #统计字符#

统计字符

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

简单题,调函数 或者自己判断也行
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        int word=0;
        int space=0;
        int num=0;
        int other=0;
        char[] c=str.toCharArray();
        for(int i=0;i<c.length;i++){
            if(Character.isLetter(c[i])){word++;}
            else if(Character.isWhitespace(c[i])){space++;}
            else if(Character.isDigit(c[i])){num++;}
            else { other++;}
        }
        System.out.println(word);
        System.out.println(space);
        System.out.println(num);
        System.out.println(other);
    }
}


全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 13:05
点赞 评论 收藏
分享
但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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