ADVERTISEMENT
ADVERTISEMENT

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

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.