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
}
}
A
a
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.ch1
and ch2
using the System.out.println()
method, which outputs the corresponding char
values of integers 65
and 97
, respectively.