| 
 | 1 | +package String;  | 
 | 2 | + | 
 | 3 | +public class Main {  | 
 | 4 | + public static void main(String[] args) {  | 
 | 5 | + // 1. Printing Statements  | 
 | 6 | + System.out.println("John said 'Java is fun and easy'");  | 
 | 7 | + System.out.println("John said \"Java is fun and easy\"");  | 
 | 8 | + | 
 | 9 | + // 2. Converting Numeric Types to Characters  | 
 | 10 | + char char1 = (char) 99; // 'c'  | 
 | 11 | + char char2 = (char) 225; // 'á'  | 
 | 12 | + | 
 | 13 | + System.out.println("\nCharacter for 99: " + char1);  | 
 | 14 | + System.out.println("Character for 225: " + char2);  | 
 | 15 | + | 
 | 16 | + // 3. Converting Characters to Integers  | 
 | 17 | + char ch1 = 'A';  | 
 | 18 | + char ch2 = '!';  | 
 | 19 | + char ch3 = '*';  | 
 | 20 | + char ch4 = 'i';  | 
 | 21 | + | 
 | 22 | + int int1 = (int) ch1; // ASCII value of 'A'  | 
 | 23 | + int int2 = (int) ch2; // ASCII value of '!'  | 
 | 24 | + int int3 = (int) ch3; // ASCII value of '*'  | 
 | 25 | + int int4 = (int) ch4; // ASCII value of 'i'  | 
 | 26 | + | 
 | 27 | + System.out.println("\nASCII value of 'A': " + int1);  | 
 | 28 | + System.out.println("ASCII value of '!': " + int2);  | 
 | 29 | + System.out.println("ASCII value of '*': " + int3);  | 
 | 30 | + System.out.println("ASCII value of 'i': " + int4);  | 
 | 31 | + | 
 | 32 | + // Optional: Get numeric value of a character  | 
 | 33 | + char ch = '5';  | 
 | 34 | + int numericValue = Character.getNumericValue(ch); // 5  | 
 | 35 | + | 
 | 36 | + System.out.println("\nNumeric value of '5': " + numericValue);  | 
 | 37 | + }  | 
 | 38 | +}  | 
0 commit comments