Google News
logo
Java Program to convert int type variables to char
In the following examples of Java program that demonstrates how to convert int type variables to char :
Program :
public class IntToCharExample {
    public static void main(String[] args) {
        int num1 = 65; // integer value 65
        int num2 = 97; // integer value 97
        char ch1 = (char) num1; // convert int to char
        char ch2 = (char) num2; // convert int to char
        System.out.println(ch1); // output: A
        System.out.println(ch2); // output: a
    }
}
Output :
A
a
In this program, we have defined two int variables num1 and num2 with the values 65 and 97, respectively. We then assign these variables to char variables ch1 and ch2 using the type casting operator (char), which converts the int values to their corresponding char values based on the ASCII table.

Finally, we print the values of ch1 and ch2 using the System.out.println() method, which outputs the corresponding char values of integers 65 and 97, respectively.