<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.Scanner;

/* Methods for generating random numbers and letters
 */
public class MyRandom {
  
  /* = a random integer in [lo..hi]
   */
  public static int randInt(int lo, int hi) {
    return (int) (Math.random()*(hi-lo+1)) + lo;
  }
  
  /* = a random type double number in [lo..hi)
   */
  public static double randDouble(double lo, double hi) {
    return Math.random()*(hi-lo)+lo;
  }
  
  /* Example method calls
   */
  public static void main(String[] args) {

    Scanner keyboard= new Scanner(System.in);
    System.out.println("Enter lower bound: ");
    int L= keyboard.nextInt();
    System.out.println("Enter upper bound: ");
    int R= keyboard.nextInt();

    int r= randInt(L, R);
    System.out.println("Random int in [" 
                     + L + ".." + R + "]:  " + r);
    
    double d= randDouble(L, R);
    System.out.println("Random number in [" 
                       + L + "," + R + "):  " + d);
    
    // Calculate the mean of 5 random integers in [L..R]
    int sum=0, n=5; 
    for (int k=0; k&lt;n; k++) {
      r= randInt(L,R);
      System.out.println(r);
      sum= sum + r;
    }
    System.out.println("Average is " + (double) sum/n);
    /* Below is an incorrect statement in this part of the method:
     *      System.out.println(k);
     * It's wrong because the scope of variable k ends with the for loop.
     * Variable k is said to be "local" to the for loop.
     */
  } //method main
    
  /* = a random letter in [A..Z] if UL is 1,
   * in [a..z] if UL is 0, otherwise return '?'.
   */
  public static char randLetter(int UL) {
    int rank= randInt(1,26);
    char letter= '?';
    
    if (UL==1)
      letter= (char) ('A'+rank-1);
    else if (UL==0)
      letter= (char) ('a'+rank-1);
    
    return letter;
  }
  
}//class MyRandom</pre></body></html>