Wednesday, October 5, 2016

// // Leave a Comment

Java Program To Find The Character Of An ASCII Code

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.

/**
 *
 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 *
 * Exercise 2.23 - Find the character of an ASCII code
 *
 */ 

import java.util.Scanner;

public class Ex02_23 {

    public static void main(String[] args) {
        
        // Display Program Information
        System.out.println("This Program Displays The Characters Of An ASCII Code.\n");

        // create Scanner 
        Scanner input = new Scanner(System.in);

        // prompt user to enter details
        System.out.println("Enter an ASCII code (an integer between 0 and 127):");
        int aSCIICode = input.nextInt();

        // convert ASCII code to the equivalent character
        char displayCharacter = (char) aSCIICode;

        // display the result
        System.out.println("The character is " + displayCharacter + "\n");
    }
}

Click here to see other solutions to Introduction to Java Programming.

0 comments:

Post a Comment


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately.

Thanks.