import java.util.Scanner;
public class AsciiValue {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = scanner.next().charAt(0);
int asciiValue = ch;
System.out.println("The ASCII value of " + ch + " is " + asciiValue);
}
}
Enter a character: 18
The ASCII value of 1 is 49
Scanner
class to read a character input by the user. We then store the ASCII value
of the character in an integer variable called asciiValue
.