Home »
Kotlin »
Kotlin programs »
Kotlin string programs
Kotlin program to check whether a character is an Alphabet, a Digit or a Special character
Kotlin | Check character is alphabet, digit or special character: Here, we are going learn how to check whether a given character is an alphabet, a digit or a special character in Kotlin programming language?
Submitted by IncludeHelp, on April 27, 2020
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
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