Question: Complete the following program so that it reverses the order of the values in data, then prints it out. In the first version of the

Complete the following program so that it reverses the order of the values in data, then prints it out.

In the first version of the program there is only one array and its values are reversed with some fairly tricky programming.

import java.io.* ; class ReverserVersion1 { public static void main ( String[] args ) { int[] data = {1,2,3,4,5,6,7,8,9,10,11,12,13,14}; // reverse the data for ( int j=0; j < be careful here; j++) { } // write out the new data for ( int j=0; j < data.length; j++) { } } } 

Now write another program that uses two arrays. The first array data is not changed. The second array result gets the elements of data in reversed order.

import java.io.* ; class ReverserVersion2 { public static void main ( String[] args ) { int[] data = {1,2,3,4,5,6,7,8,9,10,11,12,13,14}; int[] result = // copy the data in reversed order to result for ( int j=0; j < be careful here; j++) { } // write out the result for ( int j=0; j < result.length; j++) { } } } 

This version of the program is much easier, but costs more in memory. Usually this is a cost you should be willing to pay. In the very old days of computing, programmers would pick the solution that used the least memory, and often the cost was difficult code.

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!