English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

How to assign an int value to a char variable in Java

Assigning an int value to a char variable in Java considers the ASCII value and displays the associated character/Number.

Here, we have a character.

char val;

Now assign an int value to it.

val = 77;

Now, when you print the value of 'val', it will display the character associated with the value (ASCII)77Associated Characters.

Here is the complete example.

Example

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

Output Result

Value: M