Exam 8: Arrays

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which of the following println statements will display the last myScores element in an array of 10?

Free
(Multiple Choice)
4.8/5
(82)
Correct Answer:
Verified

C

When using an array with all elements used, why would a programmer use a loop control variable from 0 to one less than the size of the array? Give an example.

Free
(Essay)
4.8/5
(81)
Correct Answer:
Verified

When an application contains an array and you want to use every element of the array in some task, it is common to perform loops that vary the loop control variable from 0 to one less than the size of the array. For example, if you get input values for the elements in the array, alter every value in the array, sum all the values in the array, or display every element in the array, you need to perform a loop that executes the same number of times as there are elements.

When working with arrays, why is it beneficial to use a loop with a declared symbolic constant equal to the size of the array?

Free
(Essay)
4.8/5
(88)
Correct Answer:
Verified

It is convenient to declare a symbolic constant equal to the size of the array and use the symbolic constant as a limiting value in every loop that processes the array. That way, if the array size changes in the future, you need to modify only the value stored in the symbolic constant, and you do not need to search for and modify the limiting value in every loop that processes the array.

When you create an array variable, memory space is automatically reserved.

(True/False)
4.9/5
(82)

When any primitive type is passed to a method, the ____________________ is passed.

(Short Answer)
4.8/5
(84)

Match each term with the correct statement below. -Hold memory addresses where values are stored

(Multiple Choice)
4.9/5
(82)

When a method returns an array reference, you include ____ with the return type in the method header.

(Multiple Choice)
4.9/5
(83)

It is a good programming practice to ensure that a subscript to an array does not fall below zero, causing a(n) ____.

(Multiple Choice)
4.7/5
(91)

In Java, boolean array elements automatically are assigned the value ____.

(Multiple Choice)
4.8/5
(72)

Many programmers feel that breaking out of a for loop early disrupts the loop flow and makes the code harder to understand.

(True/False)
4.8/5
(74)

When you create an array of objects, each reference is assigned the value ____.

(Multiple Choice)
4.9/5
(75)

In which of the following statements is the value of myVals null?

(Multiple Choice)
4.9/5
(77)

public class CostArray { public static void main(String[] args) { double[] costs = new double[3]; costs[0] = 5.00; costs[1] = 7.00; costs[2] = 9.00; System.out.println(costs[3]); } } Once the above code is compiled and executed, an error message is generated. Explain the error message that will result and explain the reason for the error.

(Essay)
4.8/5
(91)

When returning an array reference, square brackets are included with the return type in the method header.

(True/False)
4.9/5
(88)

What is different about passing an array to a method rather than passing a primitive type to a method?

(Essay)
4.9/5
(87)

A ____ array is one with the same number of elements as another, and for which the values in corresponding elements are related.

(Multiple Choice)
4.8/5
(77)

An instance variable or object field is also called a(n) ____________________ of the object.

(Short Answer)
4.8/5
(95)

Match each term with the correct statement below. -A primitive type

(Multiple Choice)
4.8/5
(65)

How would a programmer perform a range match when writing an application that takes into consideration different discount rates for customers? Give an example.

(Essay)
4.9/5
(74)

When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed to a method, the value is passed.

(Multiple Choice)
4.8/5
(83)
Showing 1 - 20 of 74
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)