Kotlin Program to Display All Alphabets With Examples

Greetings!
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at tutorialwing@gmail.com.

In this post, we will go through kotlin program to display all alphabets from A to Z or a to z.

1. Program to Display Alphabets Using Loop

We are going to display all alphabets in either upper case or lower case based on the option provided by user.

Sourcecode –

fun main() {

    println("Enter U or u for Uppercase, any other for Lowercase:")
    val case = readLine()

    val isUpperCase = (case == 'U'.toString()) || (case == 'u'.toString())

    var sChar = if (isUpperCase)  'A' else 'a'
    val endChar =  if (isUpperCase)  'Z' else 'z'

    println("All Characters:")

    while (sChar <= endChar) {
        print("$sChar ")
        sChar++
    }

    println("\nThe End")
}

When you run the program, output will be

Enter U or u for Uppercase, any other for Lowercase:
u
All Characters:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
The End

When you run the program, you are asked to enter one character.

  • U or u : If you want to print all characters (or alphabets) in Uppercase
  • Any other character: If you want to print all characters (or alphabets) in Lowercase

Thus, we went through Kotlin program to display alphabets from A to Z or a to z.

Support Us

If you like Tutorialwing and would like to contribute, you can email an article on any educational topic at tutorialwing@gmail.com. We would love to publish your article. See your article on Tutorialwing and help others with your knowledge. Follow Facebook, LinkedIn, Google+, Twitter, Youtube for latest updates.
Greetings!
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners