Question: ///Java: Write a program to get create, sort, print, and searches an array containing random numbers of random numbers. ? Declare an array of size

///Java: Write a program to get create, sort, print, and searches an array containing random numbers of random numbers.

? Declare an array of size 10. (an unsorted array) ? Fill each element in this array with random numbers from 1 to 20. ? Make a copy of this array. (to be sorted) ? Using the java API, sort the copy. ? Print a table showing both the unsorted and sorted arrays as shown in the sample below. ? Enter a number to search for. ? Utilizing a for each loop: ? Search for the search string in both the unsorted and sorted arrays. o Output the search value and location found as shown in the example or output the search value was not found

//Sample output

///Java: Write a program to get create, sort, print, and searches an

array containing random numbers of random numbers. ? Declare an array of

////out put that I get

size 10. (an unsorted array) ? Fill each element in this array

It's not supposed to look like that and Im unsure where I went wrong. Also the part where Im suppose to get the result for inputting a search number not included in the array is wrong as well am i'm puzzled.

////Code

import java.util.Scanner; import java.util.Random; import java.util.Arrays;

public class ArrayWork { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Random rand = new Random(); int[] array1 = new int[10]; // array size of 10 int[] array2 = new int[array1.length]; // copy of array1 int search; // user input number to search for int ele1 = 0; // element in array1 int ele2 = 0; // element in array2 int temp = 0; // temporary holder for (int i = 0; i { array1[i] = rand.nextInt(20)+1; // random number of 1-20 } // end loop array2 = Arrays.copyOf(array1, array1.length); // copy of array1 into array2 for (int i=0; i array2[j]) { temp = array2[i]; array2[i] = array2[j]; array2[j] = temp; } } } // close System.out.printf("%-20s%-20s ", "Unsorted Array", "Sorted Array"); // printing heading for both arrays for (int i = 0; i Unsorted Array Sorted Array 10 12 14 14 14 14 15 10 Please enter number to search for: 6 Search Ualue 6 found at location 1 in the unsorted array Search Ualue 6 found at location 4 in the sorted array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!