How to Convert Int to Char in Java

Today we are going to know about How to Convert Int to Char in Java, so let us take a quick look at the basic things we need to know before we can proceed. Java is an object-oriented programming language with a high level of abstraction. It is a general-purpose programming language designed to allow programmers to write code once and execute anywhere. This means that compiled Java code can run on any platform that supports Java without requiring recompilation.

Character is a single 16-bit Unicode character is represented by the char data type. It has a value range of ‘/u0000’ (or 0) to ‘/uffff’ (or 65,535 inclusive). The Unicode system’s lowest range is “u0000”. Characters are stored using the char data type.

From our elementary school days, most of us are familiar with the concept of an integer. It’s a number with no fractional portion. In other words, integers are comparable to whole numbers, except they also include negative values. As a result, non-decimal numbers can be both positive and negative

So today with the basic knowledge of Character and Integer let us start with the tutorial on How to Convert Int to Char in Java.

 

What’s the Approach?

  • Import the java. util package

 

  • Create a Class

 

  • Declare the main Function

 

  • Create A Scanner Class

 

  • Accept input from the user and store it in int variable

 

  • Use the Typecasting to Convert it to Char

 

  • Print the Char

 

Also Read:- How to convert Int to Double in Java

 

Java Program to Convert Int to Char

 

/*

 * TechDecode Tutorials

 *

 * How to Convert Int to Char

 *

 */

import java.util.*;

public class Int_to_Char

{

    public static void main(String args[])

    {

        //Declaring Scanner Class

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the Integer Value that it to be converted to Char: ");

        //Accepting users input

        int a=sc.nextInt();

        //Converting to char

        char c=(char)a;

        //Printing the char

        System.out.println("Int converted to Char is: "+ c);




    }

}

 

Output:-

How to Convert Int to Char in Java

 

Leave a Reply

Your email address will not be published.