How to Print ASCII Value in Java
Example:
Input: ch1 = 'a', ch2='b', ch3='A', ch4='B'
Output: The ASCII value of a is: 97
The ASCII value of b is: 98
The ASCII value of A is: 65
The ASCII value of B is: 66
Approach
Java
public class PrintAsciiValue {public static void main(String[] args) {char ch1 = 'a';char ch2 = 'b';char ch3 = 'A';char ch4 = 'B';int asciich1 = ch1;int asciich2 = ch2;int asciich3 = ch3;int asciich4 = ch4;System.out.println("The ASCII value of " + ch1 + " is: " + asciich1);System.out.println("The ASCII value of " + ch2 + " is: " + asciich2);System.out.println("The ASCII value of " + ch3 + " is: " + asciich3);System.out.println("The ASCII value of " + ch4 + " is: " + asciich4);}}
No comments:
Post a Comment