Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; SEOFriendlyImages has a deprecated constructor in /home/tutorig3/public_html/wp-content/plugins/seo-image/seo-friendly-images.class.php on line 2

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/tutorig3/public_html/wp-content/themes/mts_interactive/options/php-po/php-po.php on line 185
Kotlin Program to Display All Alphabets With Examples - Tutorialwing

Kotlin Program to Display All Alphabets With Examples

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.