ASCII value of a character using java:
ASCII stands for American Standard Code for Information Interchange. The ASCII values are associated with every character either it is digits, alphabets (a-z and A-Z ), special characters ( @,$,^,&..), there are 128 characters which are lies between 0 to 127.
Uppercase letters ranges between 65 to 90.
Lowercase letters ranges between 97 to 122.
Remaining are reserved for special characters.
Example ASCII value of a character:
A = 65
B = 66
C = 67
Java code to find ASCII value of a character:
import java.util.Scanner;
class Programming9
{
public static void main(String[] args)
{
//scanner is a class for creating an object
Scanner sc=new Scanner(System.in);
//input from user
System.out.print("Enter a Character: ");
//typecasting from character datatype to integer datatype
char c=sc.next().charAt(0);
int i = c;
//print the ASCII value of the character
System.out.println("ASCII value of "+c+" is "+i);
}
}
OUTPUT:
Enter a Character: P ASCII value of P is 80 Enter a Character: @ ASCII value of @ is 64