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

LeetCode - Crawler Log Folder Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala

First Unique Character in a String Java - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Add two numbers in Scala - The Coding Shala