Sunday 3 July 2016

Chapter 4 Exercise 16, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

4.16 (Random character) Write a program that displays a random uppercase letter using the Math.random() method.




public class ProgrammingEX4_16 {
 
 public static void main(String[] args) {
 
  int n = (int) (65 + Math.random() * 26);
  char c = (char) n;
   
  System.out.println("The random letter is " + c);
 
   
   
 }
 
}

No comments :

Post a Comment