Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

///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.

//output sample.

image text in transcribed

///////////////////////////////////////////////////////////////////////////

Code I have come up with but does not seem to work.

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 = scan.nextInt; // 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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago