Java program to convert int type variables to char

https:/‮w/‬ww.theitroad.com

In Java, you can convert an int type variable to a char type variable using a type casting operation. Here's an example:

int num = 65; // decimal representation of 'A'
char c = (char) num;

System.out.println("Character value: " + c); // output: A

In the above example, we define an int variable num with a value of 65, which is the decimal representation of the character 'A'. We then use type casting to convert num to a char variable c. The (char) expression is used to tell the Java compiler to treat the int value as a char.

After the conversion, the value of c is 'A', which we verify by printing it to the console using the System.out.println method.

Note that if the int value is not in the range of valid char values, the resulting char value may be an unexpected character or a question mark.