Question
I could use a little help with this code... thanks! Directions: This exercise will use command line args, arrays, and the Random class. Your Lab7.java
I could use a little help with this code... thanks!
Directions:
This exercise will use command line args, arrays, and the Random class. Your Lab7.java program will take three values on the command line.
You will need to modify main so that the args from the comamnd line are converted to ints.
Fill in the method at the bottom. Do not modify the line of code that seeds the Random number generator.
-a small positive int representing the length of the array to be dimensioned.
-a small positive int representing the minimum value to be put into the array.
-a small positive int representing the maximum value to be put into the array.
// LAB7.JAVA FILLS AN ARRAY WITH PSEUDO RANDOM INTS USING RANDOM CLASS import java.io.*; import java.util.*; public class Lab7
// Y O U M U S T M O D I F Y M A I N public static void main( String args[] ) { // WRITE AN IF STATEMENT THAT VERIFIES THE USER PUT 3 ARGS ON THE COMMAND LINE // IF THERE ARE NOT THREE ARS FROM THE COAMMND LINE THEN PRINT AND ERROR MESSAGE // AND EXIT THE PROGRAM // IF YOU MAKE IT TO HERE, YOU HAVE 3 VALUES IN THE ARGS ARRAY int dimension = // CONVERT THE [0] ARG TO AN int AND STORE INTO dimension int lo = // CONVERT THE [1] ARG TO AN int AND STORE INTO lo int hi = // CONVERT THE [2] ARG TO AN int AND STORE INTO lo int[] array = new int[dimension]; randomFill( array, lo, hi ); // you write the code for this method below printArray( array ); } public static void printArray( int array[] ) { System.out.printf("Array has %d values: ", array.length ); for( int i=0 ; i < array.length ; ++i ) System.out.print( array[i] + " " ); System.out.println(); } // FILL THE ARRAY WITH RANDOM INTS public static void randomFill( int array[], int lo, int hi ) { Random rand = new Random( 17 ); // DO NOT REMOVE THIS LINE // WRITE A LOOP THAT DOES THE FOLLOWING: // FILLS THE ARRAY WITH RANDOM INTS. // EACH RANDOM INT TACKED ONTO THE ARRAY MUST BETWEEN LO AND HI INCLUSIVE } } // END class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started