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.
Finally, we print the ascii value using the println () function.
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.
Finally, we print the ascii value using the println () function.
fun main(args: Array) {When you run the program, the output will be:
val c = 'a'
val ascii = c.toInt()
println("The ASCII value of $c is: $ascii")
}
The ASCII value of a is: 97
No comments:
Post a Comment