ADVERTISEMENT
ADVERTISEMENT

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.