Home »
Kotlin »
Kotlin programs »
Kotlin string programs
Kotlin program to check whether a character is vowel or consonant
Here, we are going to learn how to check whether a character is vowel or consonant in Kotlin programming language?
Submitted by IncludeHelp, on April 29, 2020
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.
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