Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 6 Arrays 1 Multiple Choice 1) The individual variables that together make up the array are referred to as: indexed variables subscripted variables elements of the array (d) all of the above 2) What is the correct expression for accessing the 5th element in an array named colors? colors[3] colors[4] colors[5] colors[6] Consider the following array: myArray[0] 7 myArray[1] 9 myArray[2] -3 myArray[3] 6 myArray[4] 1 myArray[5] -1 3) 4) 5) 6) 7) What is the value of myArray[myArray[1] – myArray[0]] 7 9 -3 6 The subscript of the first indexed variable in an array is: 0 1 2 3 The correct syntax for accessing the length of an array named Numbers is: Numbers.length() Numbers.length both A and B none of the above An ArrayIndexOutOfBounds error is a: compiler error syntax error logic error all of the above Which of the following initializer lists correctly initializes the indexed variables of an array named myDoubles? double myDoubles[double] = {0.0, 1.0, 1.5, 2.0, 2.5}; double myDoubles[5] = new double(0.0, 1.0, 1.5, 2.0, 2.5); double[] myDoubles = {0.0, 1.0, 1.5, 2.0, 2.5}; 8) 9) 10) 11) 12) 13) 14) 15) 16) array myDoubles[double] = {0.0, 1.0, 1.5, 2.0, 2.5}; The base type of an array may be all of the following but: string boolean long all of these may be a base type of an array. The correct syntax for passing an array as an argument in a method is: a[] a() a a[0]..a[a.length] Partially filled arrays require: a variable to track the number of array positions used the use of local variables the use of global variables all of the above Java provides a looping mechanism for objects of a collection. This looping mechanism is called a __________ loop. While For For each All of the above A _________ can occur if a programmer allows an accessor method to return a reference to an array instance variable. short circuit privacy leak partially filled array syntax error The name of the sorting algorithm that locates the smallest unsorted value in an array and places it in the next sorted position of the array is called: bubble sort merge sort radix sort selection sort A value of an enumerated type is similar to a/an: Instance variable Object of a class Named constant None of the above An array with more than one index is called a/an: partially filled array multidimensional array bidirectional array one dimensional array A type of array in which different rows can have different number of columns is called a/an: partially filled array ragged array 17) initialized array none of the above A ________ loop is a good way to step through the elements of an array and perform some program action on each indexed variable. while do…while for all of the above True/False 18) 19) 20) 21) 22) 23) 24) 25) 26) 27) 28) 29) 30) 31) An array is a collection of variables all of the same type. An array has only one public instance variable, which is named length. An arrays length instance variables value can be changed by a program. An array of chars is the same as a String in Java. An array name references a memory address. You can only use array indexed variables as arguments to methods. A method can not change the values stored in the indexed variables of an array argument. A collection class is a class whose objects store a collection of values. You may cycle through elements of a collection object using a for loop. In a vararg specification the ellipsis is not part of the Java syntax. A variable of an enumerated type can have the special value null. Java allows you to declare arrays with more than one index. A one dimensional array is also called an array of arrays. Arrays are objects that are created with new just like class objects. Short Answer/Essay 32) Write a Java statement that declares and creates an array of Strings named Breeds. Your array should be large enough to hold the names of 100 dog breeds. Declare and create an integer array that will contain the numbers 1 through 100. Use a for loop to initialize the indexed variables. What are three ways you can use the square brackets [ ] with an array name? Given the following character array char[] h = {‘H’, ‘E’, ‘L’, ‘L’, ‘O’}; Write a Java statement that will create a new String object from the character array. Write a Java method that takes an integer array as a formal parameter and returns the sum of integers contained within the array. How are arrays tested to see if they contain the same contents? Explain what the main methods array parameter, args, is used for. Write a Java method as well as any facilitator methods needed to perform a sort on an array of whole numbers in descending order. Discuss how you could represent a table of related records using a multidimensional array. Declare and create a multidimensional array to hold the first and last names of 10 people. Declare and create a 10 x 10 multidimensional array of doubles. Initialize the array created in number 11 above to -1.0. 33) 34) 35) 36) 37) 38) 39) 40) 41) 42) 43) 44) 45) Write a complete Java console application that prompts the user for a series of quiz scores. The user should type -1 to signify that the input of quiz scores is complete. Your program should then average the scores and display the result back to the user. What is the output of the following code? int[] numbers = new int[10]; for(int i=0; i < numbers.length; ++i) numbers[i] = i * 2; for(int i=0; i < numbers.length; ++i) System.out.print(numbers[i] + " "); System.out.println(); 46) What is the output of the following code? int[] numbers = new int[10]; for(int i=0; i < numbers.length; ++i) numbers[i] = i * 2; for(int i=0; i < numbers.length; ++i) System.out.print(numbers[i] / 2 + " "); System.out.println(); 47) 48) 49) 50) Write Java statements to create a collection of integers, and to initialize each element of the collection to -1 using a for each statement. Create a Java method that will take any number of double arguments and return the smallest of the group. Write a Java statement that creates an enumerated type called months that contains the twelve different months in a year. Write a Java statement that prints the month July to the console window from the enumerated list crated in question number 18 above.