How would you change the list=temp; line ONLY so that theoutput would read Apu F
ID: 3613113 • Letter: H
Question
How would you change the list=temp; line ONLY so that theoutput would read Apu Flanders Homer ?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]); }
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; } } How would you change the list=temp; line ONLY so that theoutput would read Apu Flanders Homer ?
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]); }
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; } }
Explanation / Answer
//Hope this will help you 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]); } public static void reverse(String[] list) { String[] temp = new String[list.length]; for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.