Q:

Kotlin program to check whether a character is vowel or consonant

belongs to collection: Kotlin String Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin program to find total number of vowels, con... >>
<< Kotlin program to find ASCII value of a character...