Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITE IN JAVA: Instructions Your program will first ask for a valid length which must be an integer which is 10 or greater. The program

WRITE IN JAVA:

Instructions

Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print both of these arrays. Finally, the program will print an array using all the elements which are in the two arrays but not including any duplicates. The merged array may have space for more elements than needed: extra elements at the end of the array should be set to 0 and not printed by the program.

The numbers should be added to the merged array in an alternating pattern: first from list 1, then from list 2, then list 1 again, etc. If a number in one of the arrays already appears in the merged array, then it should be ignored, and the program should alternate to the other list again. For example, if the first list begins1 2 3 10, and the second begins3 4 5 8, then the merged list would begin1324 5108.

Because the number of elements in the merged array is unknown, its size should be set to the maximum possible number of elements it should contain, and after all elements which should form the merged array appear, any remaining unfilled spaces in the array should be 0. The first 0 encountered in the array should signal the end of the "actual" elements of the array, and therefore the 0s at the end of the array should not be printed by your program.

Be sure that your output is in the format shown in the sample run, with one array on each line and each one named correctly: the Code Runner needs to be able to read the arrays that are printed in order to correctly grade your work.

Sample Run 1

Enter an array length (must be 10 or greater): 5 Enter an array length (must be 10 or greater): 20 First Array: 89 96 23 91 2 20 89 4 50 72 88 24 88 45 58 55 37 32 79 7 Second Array: 58 63 35 39 21 17 54 53 83 19 12 67 30 67 96 76 95 26 77 41 Merged Array: 89 58 96 63 23 35 91 39 2 21 20 17 54 4 53 50 83 72 19 88 12 24 67 30 45 55 76 37 95 32 26 79 77 7 41 

Sample Run 2

Enter an array length (must be 10 or greater): 10 First Array: 99 30 29 77 29 52 36 5 59 59 Second Array: 13 10 13 82 59 58 96 30 15 73 Merged Array: 99 13 30 10 29 77 82 59 52 58 36 96 5 15 73 

Sample Run 3

Enter an array length (must be 10 or greater): 50 First Array: 32 81 75 98 97 64 76 32 99 57 29 11 58 57 5 48 49 46 17 84 85 78 44 12 11 7 35 44 73 11 28 64 84 97 59 92 99 6 49 54 69 42 93 47 42 99 80 22 31 67 Second Array: 91 64 58 91 36 15 79 83 65 41 47 98 89 26 37 65 26 93 59 86 69 52 31 77 9 33 20 83 11 52 14 64 74 83 19 95 51 11 7 5 87 88 57 62 4 38 64 77 55 55 Merged Array: 32 91 81 64 75 58 98 97 36 15 76 79 83 99 65 57 41 29 47 11 89 26 5 37 48 49 46 93 17 59 84 86 85 69 78 52 44 31 12 77 9 7 33 35 20 73 28 14 74 19 92 95 51 6 54 87 42 88 62 4 38 80 22 55 67 

Milestones

Milestone 1: Write code which asks for a length input until it gets an integer 10 or greater, then creates 2 arrays of this length.

Milestone 2: Write code which fills each of the arrays with random integers which are between 1 and 100 inclusive and displays the arrays.

Milestone 3: Set up code to loop through each element of the original arrays which are to be checked and added.

Milestone 4: Make program check through each previously filled element of the merge array to see if it contains the next value to be added and add this value if it does not already appear. Prints all values of merge array, without including the 0s at the end of the 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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

7. LO.1, 2 Interpret this Regulation citation: Reg. 1.16310(a)(2).

Answered: 1 week ago