How to assign int value to char variable in Java


To assign int value to a char variable in Java would consider the ASCII value and display the associated character/ digit.

Here, we have a char.

char val;

Now assign int value to it.

val = 77;

Now, when you will print the value of “val”, it would display the character associate with the value (ASCII) 77.

The following is the complete example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char val;
      val = 77;
      System.out.print("Value: ");
      System.out.println(val);
   }
}

Output

Value: M

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements