Question: The following program is supposed to reverse the elements in the scientists array. It compiles and runs, but it doesnt work properly. The reversal does

  1. The following program is supposed to reverse the elements in the scientists array. It compiles and runs, but it doesn’t work properly.

import java.util.Arrays; public class Reverse { public static void main(String[] args) { String[] scientists

public static void reverse(String[] list) { String[] temp = Arrays.copyOf(list, list.length); for (int i-0; i

The reversal does not occur. Fix the problem by rewriting the reverse method. Hint: You’ll need to modify one line of code. Although not required, to reduce clutter, you should remove another line of code.

import java.util.Arrays; public class Reverse { public static void main(String[] args) { String[] scientists reverse(scientists); System.out.println( = {"Sheldon", "Amy", "Raj"}; scientists [0] + " + scientists[1] + " " + scientists [2]); } // end main

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code provided has a couple of issues that need addressing in order to make the reverse method wo... View full answer

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 Introduction To Programming With Java A Problem Solving Approach Questions!