In this tutorial you will learn about the Java Program to Find ASCII Value of a character and its application with practical example.
Java program to Find ASCII Value of a Character
In this tutorial, we will learn to create a Java program that will find the ASCII Value of a Character in Java programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:
- Operators in Java Programming.
- Basic Input and Output function in Java Programming.
- Basic Java Programming.
Program to Find ASCII Value of a Character:-
American Standard Code For Information Interchange stands for ASCII. The ASCII is an encoded format. In Java programming, we can take the input from the user in character format. In today’s program, we will take input in character format. Secondly, we will find the ASCII Value of a Character in the input with the help of a small program.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input character from the user for the program to find the ASCII value. 3. Finding the ASCII value for the character input. 4. Printing the American Standard Code For Information Interchange value for the user. 5. End program. |
Program:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// Java Program to multiply Two Numbers import java.util.Scanner; public class Ascii{//Creating the class for the program in public type //Body of Main function of the program public static void main(String[] args) { //Declaring the required variable for the program. char c; //Integer type variable to hold number value. // Creates a reader instance which takes // input from standard input - keyboard //Taking the input from the user System.out.print("Enter A character : "); //Scanner is imported from the import package Scanner sc = new Scanner(System.in); // Character input c = sc.next().charAt(0); int asciival = c; // println() prints the following line to the output screen //Using the System.out.println(); //Printing the ascii value of the charcter System.out.println("The ASCII value of " + c + " is: " + asciival); } } |
Output:-
In the above program, we have first initialized the required variable.
- c = it will hold the character value from the user.
Taking input characters from the user for the program.
Finding the ASCII value of the character from the code
Printing the ASCII value of the character.