ASCII to Character
Convert an integer ASCII code to its corresponding character.
BeginnerTopic: Module 1: Basic Java Programs
Java ASCII to Character Program
This program helps you to learn the fundamental structure and syntax of Java programming.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter ASCII value (0-127): ");
int code = sc.nextInt();
char ch = (char) code;
System.out.println("Character for ASCII " + code + " = " + ch);
sc.close();
}
}Output
Enter ASCII value (0-127): 65 Character for ASCII 65 = A
Understanding ASCII to Character
We cast the integer value to char to obtain the corresponding character.
Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.