Java Program to print ASCII value of a Character2 min read

In this tutorial, you will learn how to find the ASCII value of a Character in Java. Before that you need to have the knowledge of the following in Java Programming.

ASCII stands for American Standard Code for Information Interchange. It is a 7-bit character set contains 128 (0 to 127) characters. It represents the numerical value of a character.

Example: ASCII value for the character A is 65, B is 66 but a is 97, b is 98 and so on.

There are two ways to find the ASCII value of a character, we will learn both of them.

  1. Variable Assignment
  2. Using Type-Casting

1. Variable Assignment

Java internally converts the character values to ASCII value, we do not require any type of method to do so.

Output:


2. Using Type-Casting

Type-casting refers to casting of one data-type variable to another data type.

Output:


We can also take the user input for character by using Scanner class and print the ASCII value accordingly as shown in the program below.

Output:


MORE

C++ Structures

In the C/C++ programming language, the structure is user-defined data types that allow us to store the combination of different data types together. All the …
Read More

C++ Static Keyword

Static s a keyword in C++ that is when used with different types gives different meanings. static keyword can be used with variables in a …
Read More

C++ Templates

Templates in C++ are the powerful feature that allows us to write generic programs (generic classes and generic functions). A single class or function is …
Read More

C++ Friend Function

There are private and protected members in a class that is inaccessible from outside of the class, constituting one of the concepts of object-oriented programming …
Read More

this Pointer in C++

In C++, this is a keyword that refers to the current instance of a class and this pointer holds the address or points to the …
Read More

Inheritance in C++

Inheritance is one of the most important concepts of object-oriented programming. In C++, inheritance is the process of deriving the properties and behaviors of one …
Read More