Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5.13 Lab 5b: Shuffle For this program, you will shuffle two arrays of length n together. That is you will create an array of length

5.13 Lab 5b: Shuffle

For this program, you will "shuffle" two arrays of length n together. That is you will create an array of length 2n that has elements that alternate between the two length n arrays.

(1) Read in three integers (let's name them n, min1, min2) such that:

n is the length of the two arrays to shuffle

min1 is the start of the range for the values of the first array

min2 is the start of the range for the values of the second array

(2) Initialize the first array with values min1 through min1+n-1. That is, if n = 5 and min1 = 2, the first array will be:

[2,3,4,5,6] 

(3) Initialize the second array with values min2 through min2+n-1. That is, if n = 5 and min2 = 7, the first array will be:

[7,8,9,10,11] 

(4) create a third array of length 2n, and make the values alternate between the first array and second array. Using the above examples for the first and second arrays, the third array will be:

[2,7,3,8,4,9,5,10,6,11] 

(5) Print the values of the third array separated by spaces

Example output for input 5 2 7:

2 7 3 8 4 9 5 10 6 11 

import java.util.Scanner;

public class Shuffle { public static void main(String[] args){ //declare variables //read in the three input values //create the first array //create the second array //shuffle the arrays into the thrid array //Hint: first[0] gets put into shuffled[0] // second[0] gets put into shuffled[1] // first[1] gets put into shuffled[2] // second[1] gets put into shuffled[3] // first[2] gets put into shuffled[4] // second[2] gets put into shuffled[5] //This array indexing scheme can be generalized using i such that //first[i] gets put into shuffled[i*2] //figure out the pattern for second //print the shuffled 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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions