public class WriteNumbers
2: import java.util.Scanner;
4: /**
5: * Print out a list of random numbers.
6: * User chooses range and quantity.
7: *
8: * @author Mark Young (A00000000)
9: */
10: public class WriteNumbers {
12: public static void main(String[] args) {
13: // create required variables
14: Scanner kbd = new Scanner(System.in);
15: int quantity, low, high, range;
17: // introduce yourself
18: System.out.println("\n\n"
19: + "Random Number Generator\n"
20: + "-----------------------\n\n");
22: // Get user's input
23: System.out.print("How many random numbers would you like? ");
24: quantity = kbd.nextInt();
25: kbd.nextLine();
26: System.out.print("What are the lowest and highest values allowed? ");
27: low = kbd.nextInt();
28: high = kbd.nextInt();
29: kbd.nextLine();
30: System.out.println();
32: // fix input (in case user reversed order of low and high)
33: if (high < low) {
34: int temp = high;
35: high = low;
36: low = temp;
37: }
39: // calculate range of numbers
40: range = high - low + 1;
42: // generate the numbers
43: for (int i = 0; i < quantity; ++i) {
44: int num = (int)(Math.random() * range + low);
45: System.out.println(num);
46: }
47: System.out.println();
48: }
51: }