
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Kotlin Program to Print ASCII Values
In this article, we will understand how to print ascii values of characters. This is done by assigning the character to an integer value and printing those integer values.
Below is a demonstration of the same
Suppose our input is ?
Enter a character: s
The desired output would be ?
Ascii value of s is 115
Algorithm
Step 1 ? Start
Step 2 ? Declare a char as input
Step 3 ? Define the character
Step 4 ? Assign the character to an integer variable using toInt() function and store it in myResult.
Step 5 ? Display the result
Step 6 ? Stop
Example 1
In this example, we will print the ASCII values using the toInt() method in Kotlin. First, set the variable for input character ?
val input = 's'
Now, use the toInt() method to display the ASCII values ?
val myResult = input.toInt()
Let us now see the complete example to print the ASCII values
fun main() { val input = 's' println("The input value is defined as: $input") val myResult = input.toInt() println("The ASCII value of $input is: $myResult") }
Output
The input value is defined as: s The ASCII value of s is: 115
Example 2
In this example, we will print the ASCII values ?
fun main() { val input = 's' println("The input value is defined as: $input") getASCII(input) } fun getASCII(input: Char) { val myResult = input.toInt() println("The ASCII value of $input is: $myResult") }
Output
The input value is defined as: s The ASCII value of s is: 115