Random Revie Problems

Random Revie Problems#

Question 1 Which import statement must be placed at the beginning of our program to use Random?

  1. import java.util;

  2. import java.util.*;

  3. import java.io;

  4. import java.io.*;


Question 2 Write a line of code that will properly construct a Random:


Question 3 Which line will give back a random value in the range of 0 (inclusive) to 5 (exclusive)?

  1. int num = rand.nextInt(4);

  2. int num = rand.nextInt(5);

  3. int num = rand.nextInt(6);


Question 4 Which line will give back a random value in the range of 1 (inclusive) to 6 (inclusive)?

  1. int num = rand.nextInt(4) + 1;

  2. int num = rand.nextInt(5) + 1;

  3. int num = rand.nextInt(6) + 1;


Question 5 Which line will give back a random value in the range of 5 (inclusive) to 15 (inclusive)?

Hint

nextInt(range) + min, where range = max - min + 1

  1. int num = rand.nextInt(11) + 5;

  2. int num = rand.nextInt(15) + 5;

  3. int num = rand.nextInt(10) + 5;