Name ______________________________________________________________ Object Oriented Term 4 test: 1) String[] names; names = new String[ 10 ]; names[ 0 ] = "albert"; names[ 1 ] = "bertie"; names[ 2 ] = "cuthbert"; int i = 5-3; System.out.println( names[ i ] ); What is the output of the print statememnt cuthbert 2) What is an index? What are the bounds of an array? What is a bounds error? An index is an integer value which represents a position in an array or array list. The bounds are the lowest and highest legal index value; that is, 0 and one less than the length of the array/size of the array list. A bounds error occurs when an array or array list is accessed at an index that is outside the bounds. 3) myArray[5] = 6 What is the value of the index? what is the value stored in the array and the specified index? 4) explain what an Array is. An array is data structure (type of memory layout) that stores a collection of individual values that are of the same data type. 5) Without using a number how do you represent how long an array is in memory? int [] myArray = new int[10]; myArray.length 6) What is the value of r[ 0 ] after the following code has been executed? Explain. int[] r = { 1, 2, 3, 4 }; r[ 0 ] = r[ 1 ]; r[ 0 ]++; r[0] = 3 7) The following array is declared as: double[][] dArr = new double[ 8 ][ 4 ]; How many rows and columns does the above dArr have? 8 rows and 4 columns 8) for ( int i = 1 ; i <= 10 ; i++ ) System.out.println( i ); Change the above loop to a corresponding While loop int i = 0; while (i <= 10) { System.out.println( i ); i++; } 9) Complete the code so it calculates and prints out the sum of the array int[] a = { 6, 2, 3, 4, 9, 1 }; int sum = 0; for ( ; ; ) { } int sum = 0; for(int i = 0; i < a.length; i++) { sum = sum + a[i]; } System.out.println("sum = " + sum); 10) How many iterations does the following loops carry out. for (int i=0; i < 10; i++) { } System.out.println("i= " + i); 10 11) What is the name of the class that prompts a user to enter input to the console. Scanner 12) Given an integer array. Write code that reverses it's order in a new array. int[] a = { 6, 2, 3, 4, 9, 1 }; int[] a = { 6, 2, 3, 4, 9, 1 }; int[] b = new int[6]; int j = 0; for (int i = a.length - 1; i !=-1; i--) { b[j]= a[i]; j++; } for (int i =0; i< b.length; i++) { System.out.println(b[i]); } 13) Which of the following statements are true or false a) All elements of an array are of the same type - true b) An array index must be an integer true c) Arrays cannot contain string references as elements. false c) Arrays cannot contain null references as elements.- false d) two-dimensional arrays always have the same number of rows and coulumns.false e) elements of different columns in a two dimensional array can have different types. false 14) Write code that computes the maximum values of an array. Given the following array int[] a = { 6, 2, 3, 4, 9, 1 }; int[] a = { 6, 2, 3, 4, 9, 1 }; int max= 0; for (int i = 0; i