Java - Program to get ASCII value of an entered character.


IncludeHelp 12 September 2016

In this code snippet/program we will learn how we can get the ASCII value of an entered character in java?

In this program we will read a character from the user and find the ASCII value of that character in a separate variable, and print on output screen.

Java Code Snippet - Get ASCII value of an entered character

//Java - Program to get ASCII value of an entered character.

import java.util.Scanner;
 
class GetASCII
{
	public static void main(String args[])
	{
		char ch;
		short asciiValue;
		
		Scanner SC=new Scanner(System.in);
		
		System.out.print("Enter a character: ");
		ch=SC.next().charAt(0);
		
		asciiValue= (short)ch;
		System.out.println("The ASCII value of " + ch + " is " + asciiValue);
		
	}
}
    

    Enter a character: A
    The ASCII value of A is 65



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.