(a) What is printed as a result of executing the followingprogram? PLEASE GIVE A
ID: 3618987 • Letter: #
Question
(a) What is printed as a result of executing the followingprogram?PLEASE GIVE A DETAILED EXPLANATION WITH ALL THE STEPS FOR ALLTHE FUNCTIONS, 1 POINT WILL BE GIVEN FOR LAZY INPUT ANSWER IS PROVIDED BELOW
THANKS
public class ArrayTest06 { public static void main(String[] args) { int[] test = new int[3]; test[0] = test[1] = 6; test[2]=1; System.out.println(test[0] + "," + test[2]); fiddle(test, test[1]); System.out.println(test[0] + "," + test[1]); }
static void fiddle(int[] test, int element) { System.out.println(test[0] + "," + test[2] + "," +element); test[0] = 3; test[1] = 2*element; } }
Answer: 6,1 6,1,6 3,12 (a) What is printed as a result of executing the followingprogram?
PLEASE GIVE A DETAILED EXPLANATION WITH ALL THE STEPS FOR ALLTHE FUNCTIONS, 1 POINT WILL BE GIVEN FOR LAZY INPUT ANSWER IS PROVIDED BELOW
THANKS
public class ArrayTest06 { public static void main(String[] args) { int[] test = new int[3]; test[0] = test[1] = 6; test[2]=1; System.out.println(test[0] + "," + test[2]); fiddle(test, test[1]); System.out.println(test[0] + "," + test[1]); }
static void fiddle(int[] test, int element) { System.out.println(test[0] + "," + test[2] + "," +element); test[0] = 3; test[1] = 2*element; } }
Answer: 6,1 6,1,6 3,12
Explanation / Answer
please rate - thanks public class ArrayTest06 { public static void main(String[] args) { //allocate an array with 3 elements int[] test = new int[3]; //1st 2 elements will get a 6 in them test[0] = test[1] = 6; //the last will have a 2--the array now has 6,6,1in it test[2]=1; //print the 1st and last elements, so you willprint 6,1 System.out.println(test[0] + "," + test[2]); //call fiddle with the array test, and the singleelement that is the middle //element of array test (will be a 6) fiddle(test, test[1]); //print the 1st 2 elements of test (3 and12) System.out.println(test[0] + "," + test[1]); } //receive an array and a single integer (theinteger is whatever // was in the middle element of the original array) static void fiddle(int[] test, int element) { //print 1st, last elements of array, and thesingle element (6,1,6) System.out.println(test[0] + "," + test[2] + "," + element); //to the original array, set 1st element to3 test[0] = 3; //second element to 2 times the received element(2*6) = 12 test[1] = 2*element; //the array now has 3,12,1 } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.