Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//I can\'t get it to run to know what it prints The following program is suppose

ID: 3627617 • Letter: #

Question

//I can't get it to run to know what it prints

The following program is supposed to reverse the order of the elements in the simpsons array. It compiles and runs, but it doesn't work properly.

public class Reverse
{
public static void main(String[] args)
{
String[] simpsons = {"Homer", "Flanders", "Apu"};

reverse(simpsons);
System.out.println(simpsons[0] + " " + simpsons[1] + " " + simpsons[2]);
}//end main

public static void reverse(String[] list)
{
String[] temp = new String[list.length];
for (int i =0; i<list.length; i++)
{
temp[i] = list[list.length-i-1];
}
list = temp;
}//end reverse
}//end class reverse

a) What does the program print?
b) Fix the program by providing one or more lines of alternative code for the list = temp; line. You are not allowed to change any other code, just provide alternative code for that line.

Explanation / Answer

please rate - thanks public class Reverse { public static void main(String[] args) { String[] simpsons = {"Homer", "Flanders", "Apu"}; reverse(simpsons); System.out.println(simpsons[0] + " " + simpsons[1] + " " + simpsons[2]); }//end main public static void reverse(String[] list) { String[] temp = new String[list.length]; for (int i =0; i