Cast Char to Int

This program demonstrates casting a char to int.

Problem Statement

Write a Java program that casts a char to int and prints ASCII value.

Source Code

1 public class CharToIntExample {
2 public static void main(String[] args) {
3 char ch = 'Z';
4 int ascii = (int) ch;
5 System.out.println("Character: " + ch + ", ASCII: " + ascii + " - Eduinq");
6 }
7 }

Program Output

Character: Z, ASCII: 90 - Eduinq

Explanation

char ch = 'Z'; Declares character. (int) ch Casts to integer ASCII value. Conclusion: Shows type casting from char to int.

Quick Links to Explore