Examples of Conversion from Char to Int

Input : ch = ‘3’
Output : 3

Input : ch = ‘9’
Output : 9

Integer: The Integer or int data type is a 32-bit signed two’s complement integer. Its value range lies between – 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive). Its minimum value is – 2,147,483,648 and its maximum value is 2,147,483,647. Its default value is 0. The int data type is generally used as a default data type for integral values unless there is no problem with memory.

Example:

int a = 10

Character: The char data type is a single 16-bit Unicode character. Its value range lies between ‘\u0000’ (or 0) to ‘\uffff’ (or 65,535 inclusive). The char data type is used to store characters.

Example:

char ch = 'c'

Java Program to Convert Char to Int

Given a character in Java, your task is to write a Java program to convert this given character into an integer. In Java, we can convert the Char to Int using different approaches. If we direct assign a char variable to int, it will return the ASCII value of a given character. If the char variable contains an int value, we can get the int value by calling the Character.getNumericValue(char) method. Alternatively, we can use String.valueOf(char) method.

Similar Reads

Examples of Conversion from Char to Int

Input : ch = ‘3’Output : 3 Input : ch = ‘9’Output : 9...

Methods to Convert Char to Int in Java

There are numerous approaches to the conversion of Char datatype to Integer (int) datatype. A few of them are listed below....

Contact Us