Question: import java.util.Arrays; import java.util.Random; public class SortedSequence { /** Makes an array with n random values between 0-99. @param n the number of random numbers

import java.util.Arrays; import java.util.Random; public class SortedSequence { /** Makes an array with n random values between 0-99. @param n the number of random numbers @return an array with n random numbers */ public int[] generateRandom(int n) { // // TO DO // } /** Prints an array. @param array the array to print */ public void printArray(int[] array) { // // TO DO // } /** Returns the sum of an array. @param array the array to sum @return an int of the sum of the array */ public int getSum(int[] array) { // // TO DO // } public static void main(String[] args) { SortedSequence util = new SortedSequence(); int[] values = util.generateRandom(20); System.out.println(" Unsorted array of random numbers: "); util.printArray(values); System.out.println(" Sorted array:"); Arrays.sort(values); util.printArray(values); System.out.println(); int sum = util.getSum(values); System.out.println("Sum of the array is " + sum); System.out.println(); } }
For this lab we will practice using an array and define a few methods that work with arrays. Here is our starting file: SortedSequence.java This program should generate a sequence of 20 random values between 0 and 99 in an array, prints the array, sorts and prints it, finds the sum of the elements and prints the sum. There are three methods that need to be defined: - generateRandom - printarray - getSum Complete the three methods so the program outputs something similar to this: Unsorted array of random numbers: Sorted array: Sum of the array is 1141
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
