Kotlin Program to Check Whether an Alphabet is Vowel or Consonant

Kotlin Program to Check Whether an Alphabet is Vowel or Consonant: To check whether ch is vowel or not, we check if ch is any of: (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) . Unlike Java, this is done using if..else expression as opposed to the if..else statement. If the alphabet is any of the vowels, “vowel” string is returned. Else, “consonant” string is returned.

Kotlin Program to Check Whether an Alphabet is Vowel or Consonant

Source Code

fun main(args: Array<String>) {

    val ch = 'i'

    val vowelConsonant = if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') "vowel" else "consonant"

    println("$ch is $vowelConsonant")
}

Output