(a) What is printed as a result of executing the followingprogram? PLEASE GIVE A
ID: 3618986 • Letter: #
Question
(a) What is printed as a result of executing the followingprogram?PLEASE GIVE A DETAILED EXPLANATION OF STEPS, I WILL VOTE 1POINT FOR LAZY INPUT, LIFESAVER FOR DETAILED EXPLANATION ANSWER IS PROVIDED BELOW THANKS
public class Array07 { public static void main(String[] args) { String[] test = new String[3]; test[0] = "Understand"; test[1] = "Speak"; test[2] = "Trouble"; System.out.println(test[0] + ", " + test[1]); String ttt=fiddle(test, 2); System.out.println(test[2] + ": " +ttt); } static String fiddle(String[] sa, int element) { System.out.println(sa[1] + "," + element); String a=""; for(int i=0;i<sa.length;i++) a=sa[i].charAt(element)+a; return a; } } (10 marks)
ANSWER:
Understand, Speak Speak,2 Trouble: oed (a) What is printed as a result of executing the followingprogram?
PLEASE GIVE A DETAILED EXPLANATION OF STEPS, I WILL VOTE 1POINT FOR LAZY INPUT, LIFESAVER FOR DETAILED EXPLANATION ANSWER IS PROVIDED BELOW THANKS
public class Array07 { public static void main(String[] args) { String[] test = new String[3]; test[0] = "Understand"; test[1] = "Speak"; test[2] = "Trouble"; System.out.println(test[0] + ", " + test[1]); String ttt=fiddle(test, 2); System.out.println(test[2] + ": " +ttt); } static String fiddle(String[] sa, int element) { System.out.println(sa[1] + "," + element); String a=""; for(int i=0;i<sa.length;i++) a=sa[i].charAt(element)+a; return a; } } (10 marks)
ANSWER:
Understand, Speak Speak,2 Trouble: oed
Explanation / Answer
please rate - thanks public class Array07 { public static void main(String[] args) { String[] test = new String[3]; //initialize the 1st element of test (index 0) to"understand" test[0] = "Understand"; //the 2nd element (index 1) to "speak" test[1] = "Speak"; //the 3rd element (index 3) to"Trouble" test[2] = "Trouble"; //output the 1st 2 elements //this outputs Understand, Speak System.out.println(test[0] + ", " + test[1]); //call method fiddle sending it array test andthe number 2. the results //will be put into the string ttt String ttt=fiddle(test, 2); //print the last element of test followed by theresults return from fiddle //which are in ttt and is oed System.out.println(test[2] + ": " +ttt); } //fiddle receives a string array and an integerand returns a single string element static String fiddle(String[] sa, int element) { //output the element with index 1 of the arraythat was sent (Speak) followed by the //integer that was sent(2) System.out.println(sa[1] + "," + element); //set string a to have nothing in it String a=""; //for the number of elements in the array thatwas passed to the function(3) for(int i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.