Tuesday, October 4, 2016

// // Leave a Comment

Java Program To Display Random Character

The program below is the solution to Liang's Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.22.

Question: Write a program that displays a random uppercase letter using the System.CurrentTimeMillis() method.

 * @Author: Aghatise Osazuwa
 * Website: www.cscprogrammingtutorials.com
 * Exercise 2.22 - Random character

public class Ex02_22 {

    public static void main(String[] args) {
        // Display Program Information
        System.out.println("This Program Displays A Random Upper-case Letter "
                + "Using The System.CurrentTimeMillis() Method.");
        // obtain current time
        long time = System.currentTimeMillis();
        // display random upper-case letter
        long value = 'A' + time % ('Z' - 'A' + 1);
        // display the upper-case letter
        System.out.print("Random Letter: " + (char) value + "\n");

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


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. To get notified of replies or follow-up comments, click the box next to notify me.