How to Convert Char to Int in Java

Today we are going to know about How to Convert Char to Int in Java, so let us take a quick look at the basic things we need to know before we can proceed. Java is an object-oriented programming language with a high level of abstraction. It is a general-purpose programming language designed to allow programmers to write code once and execute anywhere. This means that compiled Java code can run on any platform that supports Java without requiring recompilation.

Character is a single 16-bit Unicode character is represented by the char data type. It has a value range of ‘/u0000’ (or 0) to ‘/uffff’ (or 65,535 inclusive). The Unicode system’s lowest range is “u0000”. Characters are stored using the char data type.

From our elementary school days, most of us are familiar with the concept of an integer. It’s a number with no fractional portion. In other words, integers are comparable to whole numbers, except they also include negative values. As a result, non-decimal numbers can be both positive and negative

So today with the basic knowledge of Character and Integer let us start with the tutorial on How to Convert Char to Int in Java.

 

What’s the Approach?

  • Create a Class.

 

  • Declare the main Function

 

 

  • Create an int variable and assign it to the char variable.

 

  • Print the int variable.

 

Also Read:- How to convert Int to Double in Java

 

Java Program to Convert Char to Int

 

/*

 * TechDecode Tutorials

 *

 * How to Convert Char to Int

 *

 */

class Char_to_Int

{

    public static void main(String args[])

    {

        //Declaring char varaible

        char c='A';

        //Converting char and Storing in Int

        int a=c;

        //Printing

        System.out.println("Char " + c + " = Int value " +a);

       

    }

}

Output:-

How to Convert Char to Int in Java

Leave a Reply

Your email address will not be published.