CS 180 Chapter 7 Quiz Questions

Ace your homework & exams now with Quizwiz!

What would 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.

What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;

a = 5

When an array's reference variable is passed to a method __________.

all changes are saved because a copy of the reference to the memory address is passed

In memory, an array of String objects __________.

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

Each array in Java has a public field named __________ that contains the number of elements in the array.

length

What would be the result after the following code is 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 result after the following code is 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}

An array's subscripts always starts with __________.

zero

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 value of x[8] after the following code is 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

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

A reference to the String "ghi"

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

What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; }

The value variable will contain the lowest value in the numbers array.

15. What would be the result after the following code is executed? 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]; }

This would cause the program to crash.

The __________ indicates the number of elements the array can hold

size declarator

Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement.

str[0].toUpperCase();

A(n) __________ is used as an index to pinpoint a specific element within an array.

subscript

When an individual element of an array is passed to a method __________.

the method does not have direct access to the original array


Related study sets

Vývinová psychológia zápočet - spol. a kultúrna podmienenosť vývinových zmien

View Set

Patho Cellular Adaptation, Injury, Death

View Set

Med-Surge Endocrine Level 3 Questions

View Set

Prep U: Chapter 26: Growth and Development of the Toddler

View Set

The importance of homeostasis in the body

View Set