kotlin 分割字符

Given a character, we have to check whether it is vowel or consonant.

给定一个字符,我们必须检查它是元音还是辅音。

Example:

例:

    Input:
    ch = 'A'

    Output:
    'A' is a vowel.

    Input:
    ch = 'H'

    Output:
    'H' is a consonant.

检查Kotlin中字符是元音还是辅音的程序 (Program to check whether a character is vowel or consonant in Kotlin)

package com.includehelp.basic

import java.util.*

//Main Function, entry Point of Program
fun main(args: Array<String>) {
    // InputStream to get Input
    val scanner = Scanner(System.`in`)

    //Input Character
    print("Enter Character : ")
    val c = scanner.next()[0]
    
    when (c) {
        'a','e' ,'i' ,'o' ,'u','A','E','I','O','U' -> println("The given character $c is vowel")
        else -> println("The given character $c is consonant")
    }
}

Output

输出量

Run 1:
Enter Character : d
The given character d is consonant
---
Run 2:
Enter Character : A
The given character A is vowel
---
Run 3:
Enter Character : u
The given character u is vowel


翻译自: https://www.includehelp.com/kotlin/check-whether-a-character-is-vowel-or-consonant.aspx

kotlin 分割字符

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐