题解 | #统计字符#

统计字符

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


import java.util.Scanner

fun main(args: Array<String>) {
    val read = Scanner(System.`in`)
    while (read.hasNextLine()) {
        val a = read.nextLine()
        var digits = 0
        var letters = 0
        var others = 0
        var spaces = 0

        for (i in a) {


            if (i.isDigit()) {
                digits++

            } else if (i.isLetter()) {
                letters++

            } else if (i.isWhitespace()) {

                spaces++

            } else {
                others++
            }
        }
        println(letters)
        println(spaces)
        println(digits)
        println(others)
    }
}

#kotlin#
全部评论

相关推荐

码砖:求职岗位要突出,一眼就能看到,教育背景放到最后,学校经历没那么重要,项目要重点突出
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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