Conversion from int to char


 

Conversion from int to char

In this tutorial we will learn how to convert an int type value to char type data.

In this tutorial we will learn how to convert an int type value to char type data.

Conversion from int to char:

In this tutorial we will learn how to convert an int type value to char type data.

Description:

This program will take an int value from console and provide a conversion to char type data. The line int myint = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and store in myint variable. The line char mychar = (char)(myint); converts the myint int type value to mychar char type data.

Code:

import java.io.*;

class inttochar {
	public static void main(String[] args) {
		try {
			BufferedReader buffreader = new BufferedReader(
					new InputStreamReader(System.in));
			System.out.println("Enter the int value:");
			int myint = Integer.parseInt(buffreader.readLine());
			char mychar = (char) (myint);
			System.out.println("Convert value from int to char is: " + mychar);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Ads