The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.23.
Question: Write a program that receives an ASCII code (an integer between 0 and 127) and displays its character. For example, if the user enters 97, the program displays character a.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.23 - Find the character of an ASCII code<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class Ex02_23 {<br /><br /> public static void main(String[] args) {<br /> <br /> // Display Program Information<br /> System.out.println("This Program Displays The Characters Of An ASCII Code.n");<br /><br /> // create Scanner <br /> Scanner input = new Scanner(System.in);<br /><br /> // prompt user to enter details<br /> System.out.println("Enter an ASCII code (an integer between 0 and 127):");<br /> int aSCIICode = input.nextInt();<br /><br /> // convert ASCII code to the equivalent character<br /> char displayCharacter = (char) aSCIICode;<br /><br /> // display the result<br /> System.out.println("The character is " + displayCharacter + "n");<br /> }<br />}<br /> |
Click here to see other solutions to Introduction to Java Programming.