ASCII value of character

The term ASCII (American Standard Code for Information Interchange) refers to a defined character encoding. It assigns certain codes to characters such as letters, digits and punctuation marks. The ASCII code is used to specify how the characters are displayed by electronic devices – such as PCs or smartphones. This is an important part of many programming operations.

Code Explanation

5Initializes the variable reader of type Scanner with a new Scanner object with the input Parameter (to read from the standard input)
6Declares the variables character of type char
7Declares the variables asciiValue of type int
9 – 10Prompts the user to enter a character of type char. The value is stored in the variable named character
13In this line of code the integer value of the character of type char is stored in the variable asciiValue
14 – 15Outputs the ASCII value of the character by outputting the Variable asciiValue
import java.util.Scanner;

class AsciiValue {
    public static void main(String[] args) {
        Scanner reader = new Scanner(;
        char character;
        int asciiValue;

        System.out.print("Please enter character: ");
        character =;

        asciiValue = (int) character;
        System.out.println("ASCII value of the character "
                + character + " is: " + asciiValue);
Please enter character: F
ASCII value of the character F is: 70