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
Program to check whether a character is vowel or consonant in Kotlin
Output
need an explanation for this answer? contact us directly to get an explanation for this answer