Kotlin Program to Find Ascii Value of a Character

In this program, we will learn to code the Kotlin Program to Find Ascii Value of a Character. Let’s understand How to Find the ASCII Value of any Character in Kotlin Programming language.

ASCII stands for American Standard Code for Information Interchange is a character encoding that uses numeric codes to represent characters. These include upper and lowercase English letters, numbers, and punctuation symbols.

In this program, we will know two ways to find the ASCII value of a character. Now, let’s see the code of the Kotlin Program to Find Ascii Value of a Character.

Kotlin Program to Find Ascii Value of a Character

// Kotlin Program to Find Ascii Value of a Character
    
  fun main() {
    val character = 'B'
    val asciiValue = character.toInt()
    
    println("Ascii value of $character is $asciiValue")
}

    

Output

Ascii value of B is 66

How Does This Program Work ?

   val character = 'B'

In this program, we have declared a variable named character. This variable is assigned a character ‘B’.

     val asciiValue = character.toInt()

Then, we convert the character to an integer using the toInt() method which converts the character to its ASCII value.

println("Ascii value of $character is $asciiValue")

Then, we print the result using the println() method in Kotlin.

This is the Kotlin Program to Find Ascii Value of a Character.

Conclusion

I hope after going through this post, you understand Kotlin Program to Find Ascii Value of a Character. We discussed two approaches in this to generate the Multiplication Table in Kotlin. We have used Both For Loop and While Loop.
If you have any doubt regarding the topic, feel free to contact us in the Comment Section. We will be delighted to help you.

Learn More:

Leave a Comment

Your email address will not be published.