Home » Blog » Write a Java program to print the ASCII values for characters entered by the user.

Write a Java program to print the ASCII values for characters entered by the user.

Character is stored in its ASCII format in java. The standard set of character known as ASCII still ranges from 0 to 127 as always.

  • Example:
import java.util.Scanner;

class FindASCII
{
	//get ASCII value of character
	public static void main(String args[])
	{
		char c,con;
		int i;
		Scanner sc;
	
		do
		{
			sc=new Scanner(System.in);
			System.out.println("Enter Any Character");
			c=sc.next().charAt(0);
		
			i=c;
			System.out.println("ASCII Value Of "+c+" Is "+i);
			
			System.out.println("Do You Want To Continue (y/n) ");
			con=sc.next().charAt(0);
		}while(con=='y' || con=='Y');
	}
}
  • OutPut
Enter Any Character
T
ASCII Value Of T Is 84
Do You Want To Continue (y/n)
n

 

Tags:

Leave a Reply

Your email address will not be published.