Helping Information

Find ASCII Value of a character in Java.

Find ASCII Value of a character in Java.

Problem Definition: Java Program to Find ASCII Value of a Character.

on the positive side if you don’t have latest version of Java click here.

In this program, you’ll learn to find ASCII. And, display the value of a character in Java. This is done using type-casting. The normal variable assignment operations.

Java Program to Find ASCII

Example: Program of Find ASCII Value of a Character.

public class AsciiValue {

    public static void main(String[] args) {

        char ch = 'a';
        int ascii = ch;
        // You can also cast char to int
        int castAscii = (int) ch;

        System.out.println("The ASCII value of " + ch + " is: " + ascii);
        System.out.println("The ASCII value of " + ch + " is: " + castAscii);
    }
}

Output:

When you run this program, the output will be.

The ASCII value of "a" is: 97

As shown above program, character “a” is store in a “char” variable “ch”. Identically, double quotes (” “) are used to declare strings. We use single quotes (‘ ‘) to declare characters.

In particular, to find the ASCII value of “ch”. We just assign “ch” to an “int” variable “ascii”. Internally, Java converts the character value to an ASCII value.

Therefore, We can also cast the character “ch”. It’s case into an integer using “(int)”. First thing to remember, casting is converting variable from one type to another. Further, char variable “ch” is convert to an “int” variable “castAscii”.

With this in mind, we print the “ascii” value. Using the “println()” function.

On this side, If we notice computer. It’s only understand language of low level. For this reason, Everything is made up of binary. Its simple and easy to computer to analyse the binary.

As a result, Computer understand the binary language. Henceforth, if you want to know what is ASCII Value. The value of small alphabets. Also, value of capital alphabets, digits, special character also special symbol.

Related Post:

  1. Java Program to Copy File
  2. Java Program to Rename File
  3. Java Program to List Files in a Directory
  4. Java Program to Create a Directories

Leave a Reply

Your email address will not be published. Required fields are marked *