-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP05_AsciiValueOfChar.java
More file actions
31 lines (26 loc) · 1.19 KB
/
Copy pathP05_AsciiValueOfChar.java
File metadata and controls
31 lines (26 loc) · 1.19 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
package programs;
/**
* ============================================================
* PROGRAM 05: ASCII Value and Character Conversions
* ============================================================
* Problem: WAP to print the ASCII / Unicode value of characters
* and perform case toggling arithmetic.
* ============================================================
*/
public class P05_AsciiValueOfChar {
public static void main(String[] args) {
char[] sampleChars = {'A', 'Z', 'a', 'z', '0', '9', '$', '@', ' '};
System.out.println("=== CHARACTER TO ASCII TABLE ===");
for (char c : sampleChars) {
int ascii = (int) c;
System.out.printf(" Character: '%c' -> ASCII Value: %3d (Hex: 0x%02X)%n", c, ascii, ascii);
}
System.out.println("\n=== CASE CONVERSION VIA ASCII ARITHMETIC (±32) ===");
char lower = 'g';
char upper = (char) (lower - 32); // 'a'(97) - 32 = 'A'(65)
System.out.printf(" Lowercase '%c' - 32 = Uppercase '%c'%n", lower, upper);
char upperK = 'K';
char lowerK = (char) (upperK + 32);
System.out.printf(" Uppercase '%c' + 32 = Lowercase '%c'%n", upperK, lowerK);
}
}