Cast Int to Char
This program demonstrates casting an int to char.
Problem Statement
Write a Java program that casts an int to char and prints the character.
Source Code
| 1 | public class IntToCharExample { |
| 2 | public static void main(String[] args) { |
| 3 | int code = 66; |
| 4 | char ch = (char) code; |
| 5 | System.out.println("Integer: " + code + ", Character: " + ch + " - Eduinq"); |
| 6 | } |
| 7 | } |
Program Output
Integer: 66, Character: B - Eduinq
Explanation
An integer variable code is declared with value 66, and (char) code casts it to the corresponding character 'B', showing type casting from int to char.