Cast Integer to Character

This program casts an integer to a character.

Problem Statement

Write a Java program that casts an integer to a character and prints it.

Source Code

1 public class IntToChar {
2 public static void main(String[] args) {
3 int code = 65;
4 char ch = (char) code;
5 System.out.println("Integer: " + code + ", Character: " + ch + " - Eduinq");
6 }
7 }

Program Output

Integer: 65, Character: A - Eduinq

Explanation

An integer variable code is declared, and (char) code casts it to its corresponding character, after which both values are printed, showing type casting from int to char.

Quick Links to Explore