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.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.22 - Random character<br /> *<br /> */ <br /><br />public class Ex02_22 {<br /><br /> public static void main(String[] args) {<br /> <br /> // Display Program Information<br /> System.out.println("This Program Displays A Random Upper-case Letter "<br /> + "Using The System.CurrentTimeMillis() Method.");<br /> // obtain current time<br /> long time = System.currentTimeMillis();<br /> // display random upper-case letter<br /> long value = 'A' + time % ('Z' - 'A' + 1);<br /> // display the upper-case letter<br /> System.out.print("Random Letter: " + (char) value + "n");<br /> }<br />}<br /> |
Click here to see other solutions to Introduction to Java Programming.