Friday, November 8, 2019

How to Kotlin Program to Find ASCII value of a character

In the above program Kotlin Program to Find ASCII value of a character, the character a is stored in variables char, ch. Similar to Java, double quotes ("") are used to declare strings, we use single quotes ('') to declare characters.
Now, to find the ASCII value of character, we use the Kotlin built-in function named toInt (). This converts a Char value into an Int value.
This converted value is then stored in an ascii variable.
How to Kotlin Program to Find ASCII value of a character

Finally, we print the ascii value using the println () function.
fun main(args: Array) {
    val c = 'a'
    val ascii = c.toInt()
    println("The ASCII value of $c is: $ascii")
}
When you run the program, the output will be:
The ASCII value of a is: 97 

No comments:

Post a Comment