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

x.Hm How many times does the following loop body (the print statement) execute?

ID: 3614967 • Letter: X

Question

x.Hm How many times does the following loop body (the print statement) execute? int[] a = {5,7,12,19,31,50}; for(int x: a) { System.out.println(x); } None. There is a compiler error. 1 2 4 6 How many times does this loop body execute? int[] a = {5,7,12,19,31,50}; for(int i = 2; i < a.length; i += 3) { System.out.println(a[i]); } None. There is a compiler error. 1 2 4 6 True or false, the following will correctly print all 3 values 5, 10, and 15. ArrayList<Integer> al; Iterator<Integer> p = al.iterator(); al.add(5); al.add(10); al.add(15); while(p.hasNext()) { System.out.println(p.next()); } True False True or false. The following method will print all the elements in the ArrayList a: public static void print(ArrayList<Integer> a) { Iterator<Integer> p = a.iterator(); while( p.hasNext() ) { System.out.println(p.next()); } } True False For the code below: int[][] a = { {1,2,3}, {3,4,5}, {6,7,8}}; for(int j = 0; j < 3; j++ ) { for(int i = 0; i < 3; i++) { System.out.printf("%3d", a[i][j]); } System.out.println(); } which statement best describes what it does? Prints 3 output lines. Each line contains the values of one row of the array. line. Prints 3 output lines. Each line contains the values of one column of the array. Prints 1 output line. The values are printed in row order. Prints 1 output line. The values are printed on column order. For the method r below assume that the array a is sorted in increasing order and contains no duplicates: public static int r(int[] a, int x) { int p = -1; for(int i = 0; i < a.length; i++) { if ( a[i] <= x ) { p = i; } } return p + 1; } which statement best describes what it does? returns the index of the first element in the array that is equal to x returns the index of the first element in the array that is greater than x returns the number of elements in the array that are < x. returns the number of elements in the array that are <= x. next prev start Is the substring method of the String class an accessor or a mutator? accessor mutator A non-static method in a class can access any data member of the class only the non-static data members of the class only the static data members of the class next prev start A static method in a class can access any data member of the class only the non-static data members of the class only the static data members of the class Which of these classes is immutable? I. Integer II. String III. StringBuffer IV. ArrayList Only I. Only II. Only I and II Only II and III All except IV Al

Explanation / Answer

x.