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

Shell Script to Create a Simple Calculator - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala

Java Program to Find GCD or HCF of Two Numbers - The Coding Shala