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