ADVERTISEMENT
ADVERTISEMENT

Home » Kotlin » Kotlin programs » Kotlin string programs

Kotlin program to find ASCII value of a character

Kotlin | Finding ASCII of a character: Here, we are going to learn how to find the ASCII value of a given character in Kotlin programming language?
Submitted by IncludeHelp, on April 27, 2020

Given a character, we have to find its ASCII value.

Example:

    Input:
    c = 'A'

    Output:
    65

Program to find ASCII value of a character in Kotlin

package com.includehelp.basic

import java.util.*

//Main Function, entry Point of Program
fun main(args: Array<String>) {
    // InputStream to get Input
    val scanner = Scanner(System.`in`)

    //Input Character
    print("Enter Character : ")
    val c = scanner.next()[0]

    //Get Ascii Value of Character
    val ascii = c.toInt();

    //Print AscII Value
    println("ASCII Code of $c is $ascii");
}

Output

RUN 1:
Enter Character : A
ASCII Code of A is 65
---
Run 2:
Enter Character : a
ASCII Code of a is 97
---
Run 3:
Enter Character : 3
ASCII Code of 3 is 51
---
run 4:
Enter Character : #
ASCII Code of # is 35
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.