- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 the 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
- Related Articles
- Java Program to Print the ASCII values
- Swift Program to Print the ASCII values
- Haskell program to print ascii values
- C Program to print all ASCII values.
- C program to print the ASCII values in a string.
- How to print the ASCII values in Golang?
- Kotlin Program to Print an Integer
- Kotlin Program to Print a String
- Java program to print ASCII value of a particular character
- 8085 Program to convert two-digit hex to two ASCII values
- Python program to find the sum of Characters ascii values in String List
- Program to convert two-digit hex to two ASCII values in 8085 Microprocessor
- Python program to print the keys and values of the tuple
- Python Program to print unique values from a list
- C# program to print unique values from a list
