-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path019-Find-ASCII-Value.java
More file actions
71 lines (57 loc) · 2.36 KB
/
Copy path019-Find-ASCII-Value.java
File metadata and controls
71 lines (57 loc) · 2.36 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* ============================================================================
* Program Name : Find ASCII Value
* File Name : 019-Find-ASCII-Value.java
* Class Name : FindASCIIValue
*
* Description:
* This program demonstrates how to find the ASCII value of a character
* in Java. Every character is internally represented by a numeric value
* based on the ASCII (American Standard Code for Information Interchange)
* character set for standard characters.
*
* Objective:
* - Understand the relationship between characters and their ASCII values.
* - Learn how implicit type conversion converts a char into an int.
* - Display the ASCII value of a given character.
*
* Author : Shaik Mahaboob Basha
* Repository : 01-Core-Java
* Folder : 08-Java-Programs
* ============================================================================
*/
public class FindASCIIValue {
// The main() method is the entry point of every Java application.
public static void main(String[] args) {
// Declare and initialize a character variable.
char character = 'A';
// Convert the character to its ASCII value using implicit type casting.
int asciiValue = character;
// Display the character.
System.out.println("Character : " + character);
// Output: Character : A
// Display the ASCII value.
System.out.println("ASCII Value : " + asciiValue);
// Output: ASCII Value : 65
// Display another example using a lowercase character.
char lowerCaseCharacter = 'a';
// Convert the lowercase character to its ASCII value.
int lowerCaseASCII = lowerCaseCharacter;
// Display the lowercase character.
System.out.println("\nCharacter : " + lowerCaseCharacter);
// Output: Character : a
// Display its ASCII value.
System.out.println("ASCII Value : " + lowerCaseASCII);
// Output: ASCII Value : 97
// Display another example using a digit.
char digit = '5';
// Convert the digit to its ASCII value.
int digitASCII = digit;
// Display the digit.
System.out.println("\nCharacter : " + digit);
// Output: Character : 5
// Display its ASCII value.
System.out.println("ASCII Value : " + digitASCII);
// Output: ASCII Value : 53
}
}