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.