Computer Science JAVA -- Chapter 7

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

for the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String "ghi"

a ragged array is:

a two-dimensional array where the rows are of different lengths

what do you normally use with a partially-filled array?

an accompanying integer value that holds the number of items stored in the array

what will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};

an array of 6 values ranging from 0 through 5 and referenced by the variable x will be created

JAVA performs _________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

array bounds checking

in memory, an array of String objects:

consists of elements, each of which is a reference to a String object

JAVA limits the number of dimensions that an array may have to 15

false

an array can hold multiple values of several different data types simultaneously

false

it is common practice to use a ______ variable as a size declarator

final

which of the following for loops is valid, given the following declaration? String [] names = {"abc", "def", "ghi", "jkl"};

for (int i = 0; i < names.length; i++) System.out.println(names[i].length());

if numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

in JAVA, you do not use the new operator when you use a(n);

initialization list

which of the following is a valid declaration for a ragged array?

int[] () ragged = new int (5)[];

to return an array of LONG values from a method, use this as the return type for the method

long[]

which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int[][] x)

when an array of objects is declared, but not initialized , the array values are set to null

true

what would be the results of the following code? int[] array1 = new int [25] // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; }

value contains the lowest value in array1

what would be the results after the following code was executed? int[] x = (23, 55, 83, 19); int[] y = (36, 78, 12, 24); for (int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

what would be the results after the following code was executed? int[] x = (23, 55, 83, 19); int[] y = (36, 78, 12, 24); x = y; y = x;

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

which of the statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long [ARRAY_SIZE];

-declares array1 to be a reference to an array of long values -will allow valid subscripts in the range of 0-9 -creates an instance of an array of 10 long values

what will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess{x[1]}; ... public static void arrayProcess(int a) { a = a + 5; }

33

what will be the value of x[1] after the following code is executed? int[] x = (22, 33, 44); arrayProcess(x); ... public static void arrayProcess(int[] a) { for (int k = 0; k < 3; k++) { a[k] = a[k] + 5; } }

38

what will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int [SUB]; int y = 20; for (int i = 0; i < SUB; i++) { x[i] = y; y+= 5; }

60

when an array is passed to a method

-a reference to the array is passed -the method has direct access to the original array -it is passed just as an object

subscript numbering always starts at what method

0

if final int SIZE = 15 and int [] x = new int [SIZE]. what would be the range of subscript values that could be used with x[]?

0 through 14

what will be the the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for (int i = 0; i < SUB; i++) { x[i] = y; y += 10; }

180

given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:

str[0].toUpperCase();

when an individual element of an array is passed to a method:

the method does not have direct access to the original array

what would be the results of the following code? final int SIZE = 25; int[] array1 = new int [SIZE]; //Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; } PAY ATTENTION TO THE FOR LOOP

this would cause the program to crash

a sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order

true

an ArrayList object automatically expands in size to accommodate the items stored in it

true

declaring an array reference variable does not create an array

true

objects in an array are accessed with subscripts, just like any other data type in an array

true

once an array is created, its size cannot be changed

true


Kaugnay na mga set ng pag-aaral

Chapter 1: Taking Charge of Your Health

View Set

Understanding business 8th edition, Business Management Mid-term (Study Guide Q&A), Business 101, Intro to Business Final Review, INTRODUCTION TO BUSINESS FINAL EXAM

View Set

APES Unit 5 Progress Check MCQ Review

View Set

Forensic Accounting Final Exam Study Guide

View Set

Organizational Behavior Final 2.0

View Set

Q/A Respiratory chapter 30 and 31

View Set

Internet and Electronic Commerce

View Set

Econ Exam 3 Multiple Choice Questions

View Set