This is a program that will tell you about the process used to find out the ASCII values of characters in java
Learning Objectives:
To learn java concepts related to :
- ASCII code.
- Implicit conversion.
- Explicit conversion.
Program Objective:
The objective is to demonstrate the process of finding the ASCII code of a particular character. This is done in two ways:- Implicit conversion and Explicit conversion.The implicit conversion is performed by the compiler itself and explicit conversion is the forced conversion performed by the user.
Approach/Algorithm:
We will be initializing a character value to a variable. Then we would be first converting it integer type to find its ASCII value by implicit conversion method and then by explicit conversion method.
Source Code:
Suggested Filename:ASCIICode.java
class ASCIICode
{
public static void main(String[] args)
{
char c='a';
int n=(int)c; //explicit casting of character to integer
int n1=c; //implicit conversion of character to integer
System.out.println("The explicit converted code is :"+n);
System.out.println("The implicit converted code is :"+n);
}
}
Output…
The explicit converted code is :97
The implicit converted code is :97
Understanding Program:
int n=(int)c;
Here, we have explicitly converted the character c into integer for finding its ASCII value. This is the forced conversion by the user .
int n1=c;
Here, we have implicitly converted the character c into an integer for its ASCII value, this is not a forced conversion . The compiler automatically converts the data types.
