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
- 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](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1704/8/0/1/154659d3383004531704801155520.jpg)
![public static void reverse(String[] list) { String[] temp = Arrays.copyOf(list, list.length); for (int i-0; i](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1704/8/0/1/197659d33adcfe841704801196950.jpg)
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
The code provided has a couple of issues that need addressing in order to make the reverse method wo... View full answer
Get step-by-step solutions from verified subject matter experts
