Java Program to Convert int to char - The Coding Shala
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
- Java Program to Convert int to long
- Java Program to Convert long to int
- Java Program to Take Input From User
- Java Program to Check Prime Number
- Java Program to Find Largest of Three Numbers
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.
Comments
Post a Comment