20.0k views
22 votes
Create a program that allows the user to pick and enter a low and a high number. Your program should generate 10 random numbers between the low and high numbers picked by the user. Store these 10 random numbers in a 10 element array and output to the screen.

In java code please.

User Mayuso
by
5.2k points

1 Answer

8 votes

Answer:

import java.util.Scanner;

import java.util.Arrays;

import java.util.Random;

public class Main {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter low: ");

int low = scan.nextInt();

System.out.print("Enter high: ");

int high = scan.nextInt();

scan.close();

int rndnumbers[] = new int[10];

Random r = new Random();

for(int i=0; i<rndnumbers.length; i++) {

rndnumbers[i] = r.nextInt(high-low+1) + low;

}

for(int i=0; i<rndnumbers.length; i++) {

System.out.printf("%d: %d\\", i, rndnumbers[i]);

}

}

}

User Diogenes Creosote
by
5.2k points