Java Program to Convert int to char - The Coding Shala

Home >> Java Programs >> Convert int to char

 Hey there, welcome back to another post. In this post, we are going to learn how to convert int to char in Java.

Java Program to Convert int to char

We can convert int to char using explicit type-casting. Here, the size of int is 4 bytes and char's size is 1 byte so we need explicit type-casting.

Java Program: 

/**
 * https://www.thecodingshala.com/
 */

public class Main {

    public static void main(String[] args) {
        int num = 97;

        // explicit type casting because higher to lower data type
        // int(4 bytes) to char(1 byte)
        // char ch = num;  -> this will give error
        char ch = (char) num;
        System.out.println("Converted char is: " + ch);
    }
}

Output: 

Converted char is: a


Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.

Comments

Popular Posts from this Blog

Anti Diagonals - The Coding Shala

First Missing Positive Solution - The Coding Shala

LeetCode - Swap Nodes in Pairs Solution - The Coding Shala

Longest Substring Without Repeating Characters Java Program - The Coding Shala

Shell Script to Display the digits which are at odd positions in a given 5-digit number - The Coding Shala