Q:

Kotlin program to check whether a character is an Alphabet, a Digit or a Special character

belongs to collection: Kotlin String Programs

0

Given a character, we have to check whether it’s an alphabet, a digit or a special character.

Example:

    Input:
    c = 'A'

    Output:
    Alphabet

    Input:
    c = '@'

    Output:
    Special character

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 an Alphabet, a Digit or a Special character 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 char = scanner.next()[0]

    when {
        char.isDigit() -> println("Digit")
        char.isLetter() -> println("Alphabet")
        else -> println("Special Character")
    }
}

Output

RUN 1:
Enter Character : 5
Digit
---
Run 2:
Enter Character : F
Alphabet
---
Run 3:
Enter Character : $
Special Character

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

total answers (1)

Kotlin program to find the frequency of character ... >>
<< Kotlin program to check for Empty, Blank or NULL s...