MIS 3330 (Java Programming) Exam 2 CH: 6-9

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A(n) ____ loop is one that performs no actions other than looping.

do-nothing

The ____ loop checks the value of the loop control variable at the bottom of the loop after one repetition has occurred.

do...while

The ____ loop is the posttest loop used in Java.

do...while

The creators of Java chose ____ characters as the "extra" length for a StringBuilder object.

16

int[][] myVals = {{2, 4, 6}, {1, 3, 5, 7}}; Using the above array, what is the value of myVals.length?

2

When you place objects in order beginning with the object that has the highest value, you are sorting in ____ order.

descending

A for loop provides a convenient way to create a(n) ____ loop.

counter-controlled

Memory block

buffer

Languages such as Visual Basic, BASIC, and COBOL use ____ to refer to individual array elements.

( ) Quotations

Which of the following is NOT a valid method to increase a variable named score by 1?

++score = score + 1

When you declare int[]someNums = new int[10];, each element of someNums has a value of ____.

0

Assume d and x are integers: d = 5; x = 2 * ++d; What is the value of x?

12

for (loop = 1; loop <3; ++loop) System.out.print(1); for (loop2 = 1; loop2<3; ++loop2) System.out.print(2);

122122

int[][] myVals = {{2, 4, 6}, {1, 8, 9}, {1, 3, 5, 7}}; Using the above array, what is the value of myVals[1].length?

3

How many times will outputLabel be called? for(customer = 1; customer <= 20; ++customer) for(color = 1; color <= 3; ++color) outputLabel();

60

int[][] myVals = {{2, 4, 6, 8}, {20, 40, 60, 80} }; Using the above two-dimensional array, what is the value of myVals[1][2]?

60

In the expressions b = 8 and c = --b, what value will be assigned to the variable c?

7

You use a ____ following the closing brace of an array initialization list.

; Semicolon

You can add an item at any point in a(n) ____ container and the array size expands automatically to accommodate the new item.

ArrayList

The ____ class contains standard methods for testing the values of characters.

Character

A counted loop is the same as an indefinite loop.

False

Any string value that is input into a program can be used in arithmetic operations.

False

If you do not provide values for the elements in a two-dimensional numeric array, the values default to null.

False

If you try to use an index that is greater than 0 or less than the index of the last position in the StringBuilder object, you cause an error known as an exception and your program terminates.

False

Making a comparison to 0 is slower than making a comparison to any other value.

False

Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.

False

Parallel arrays do not necessarily have the same number of elements.

False

Programmers rarely use indefinite loops when validating input data.

False

Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.

False

Since an array name is a reference, you are able to use the = operator for assigning and the == operator for comparisons.

False

Swapping two values can be accomplished with two statements.

False

The StringBuffer class is more efficient than the StringBuilder class because it can execute multiple threads during program execution.

False

The bubble sort is the fastest and most efficient sorting technique.

False

The methods islowerCase() and toLowerCase() perform the same tasks.

False

The statements that make up a loop body will continue to execute as long as the expression value remains false.

False

The terms "literal string" and "string literal" have different meanings in Java programming.

False

When nesting loops, the variable in the outer loop changes more frequently.

False

When using parallel arrays, if one array has many possible matches, it is most efficient to place the less common items first so that they are matched right away.

False

When using the Arrays.binarySearch() method, it is not necessary for the list to be in order because the binarySearch() method will sort the items when called.

False

When working with Strings, it is necessary to explicitly set a String to null.

False

When you compare Strings with the == operator, you are comparing their values, not their memory addresses.

False

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

False

When you want to determine whether a variable holds one of many valid values, one option is to use a do...while loop to compare the variable to a series of valid values.

False

You can declare an array variable by placing curly brackets after the array name.

False

What is the output of the following code: loopCount = 1; while(loopCount < 3) { System.out.println("Hello"); loopCount = loopCount + 1; }

Hello Hello

To convert a String to an integer, you use the ____ class, which is part of java.lang and is automatically imported into programs you write. -

Integer

____ is a technique that can improve loop performance by combining two loops into one.

Loop fusion

On many keyboards, the Break key is also the ____ key.

Pause

What is wrong with the following code? x=1; while (x<5); { System.out.println (x); x++; }

Semicolon at the end of the while expression

____ is the process of arranging a series of objects in some logical order.

Sorting

Which of the following correctly declares and initializes a String object?

String greeting = "Hello";

A named object of the String class

String variable

A ____ is a class for storing and manipulating changeable data that is composed of multiple characters.

StringBuilder

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

System.out.println(vals[9]);

What is the output of the following code: loopCount = 1; while(loopCount < 3) System.out.println("Hello"); loopCount = loopCount + 1;

This is an infinite loop

A String variable name is not a simple data type.

True

In a compareTo() method, programmers often do not need specific return values but want to determine if a value is positive or negative.

True

In order to improve loop performance, it's important to make sure the loop does not include unnecessary operations or statements.

True

Since the ArrayList class is part of the java.util package, you can use the java.util.*; import statement to access it.

True

The simplest possible sort involves two values that are out of order.

True

To initialize an array, you use an initialization list of values separated by commas and enclosed within curly braces.

True

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.

True

When array elements are passed by value, a copy of the value is made and used within the receiving method.

True

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

True

When using an insertion sort, each list element is examined one at a time and moved down if the tested element should be inserted before them.

True

When working with two-dimensional arrays, the length field holds the number of rows in an array and each row has a length field that holds the number of columns in the row.

True

When you must determine whether a String is empty, it is more efficient to compare its length to 0 than it is to use the equals () method.

True

When you pass a two-dimensional array to a method, you pass the array name just as you do with a one-dimensional array.

True

You can initialize one or more variables in the first section of a for statement.

True

You can think of the single dimension of a single dimensional array as the height of the array.

True

You can use virtually any number of nested loops; however, at some point, your machine will no longer be able to store all the necessary looping information.

True

____ is the process of ensuring that a value falls within a specified range.

Validating data

To declare a two-dimensional array in Java, you type two sets of ____ after the array type.

[ ] Brackets

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

[ ] Brackets

The process of repeatedly increasing a value by some amount is known as ____.

accumulating

When you declare or access an array, you can use any expression to represent the size, as long as the expression is _____.

an integer

A literal string is a(n) ____ object.

anonymous

A literal string is called a(n) ____.

anonymous object

An unnamed object is an

anonymous object

Add characters to the end of a StringBuilder object

append()

When you place objects in order beginning with the object that has the lowest value, you are sorting in ____ order.

ascending

Programmers often refer to a ____ search as a "divide and conquer" procedure.

binary

A method that receives a two-dimensional array uses two ____ pairs following the data type in the parameter list of the method header.

brackets

In a(n) ____, you repeatedly compare pairs of items, swapping them if they are out of order, eventually creating a sorted list.

bubble sort

A StringBuilder object contains a memory block called a _____, which might or might not contain a string.

buffer

An ArrayList's ____ is the number of items it can hold without having to increase its size.

capacity

Length of a buffer

capacity

The ____ method requires an integer argument that indicates the position of the character at that position, starting at 0.

charAt()

You can initialize more than one variable in a for loop by placing a(n) ____ between the separate statements.

comma

When the String class ____ method is used to compare two Strings, it provides additional information to the user in the form of an integer value.

compareTo()

Appending strings

concatenation

System.out.println("Your name is " + yourName); The above statement is an example of ____, which is used to join Strings.

concatenation

Which Java statement creates a jagged array with six rows?

double [ ][ ] sales = new double[6][]

Which of the following statements correctly declares and creates an array to hold five double scores values?

double[] scores = new double[5]

A(n) ____ is a body with no statements in it.

empty body

A(n) ____ loop allows you to cycle through an array without specifying the starting and ending points for the loop control variable.

enhanced for

In Java, you create an enumerated data type in a statement that uses the keyword ____.

enum

The String class ____ method evaluates the contents of two String objects to determine if they are equivalent.

equals()

The String class ____ method is similar to the equals() method. As its name implies, this method does not consider case when determining if two Strings are equivalent.

equalsCase()

A(n) ____ is a kind of indefinite loop.

event-controlled

What kind of loop is this: response = keyboard.nextInt(); while (response == 1) { System.out.print ("Enter 1 to continue; 0 to stop"); response = keyboard.nextInt(); }

event-driven

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

false

The length ____ contains the number of elements in the array.

field

The Arrays class ____ method puts a particular value in each element of the array.

fill

The Arrays class ____ method assigns the specified value to each element of the specified array.

fill()

A(n) ____ is a variable that holds a value as an indicator of whether some condition has been met.

flag

A(n) ____ loop is a special loop that is used when a definite number of loop iterations is required.

for

When creating a for loop, which statement will correctly initialize more than one variable?

for(a=1, b=2)

The ArrayList class ____ method retrieves an item from a specified location in an ArrayList.

get

What is wrong with the following code? while (4>2) System.out.println ("Hi there");

infinite loop

The Character class ____ from java.lang.Object.

inherits

Object that can't be changed

immutable

Strings and other objects that can't be changed are known as ____.

immutable

Add characters at a specific location within a StringBuilder object

insert()

The ____ method lets you add characters at a specific location within a StringBuilder object.

insert()

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

int [ ] myVals;

A(n) ____ comparison is based on the integer Unicode values of the characters.

lexicographical

A loop controlled by the user is a type of ____ loop.

indefinite

Determines whether a specific character occurs within a String

indexOf()

A loop that never ends is called a(n) ____ loop.

infinite

Which of the following statements correctly initializes an array with an initialization list?

int[ ] nums = {2, 4, 8};

How would you create an array named someNumbers that holds three rows and four columns?

int[ ][ ] someNumbers = new int[3][4];

When you declare or access an array, you can use any expression to represent the size, as long as the expression is a(n) ____.

integer

One execution of any loop is called a(n) ____.

iteration

double[][] empSales = new double[5][]; The above statement declares a(n) ____ array.

jagged

With a two-dimensional array, the ____ field holds the number of rows in the array.

length

The ____ method returns the length of a String.

length()

A ____ is a structure that allows repeated execution of a block of statements.

loop

Which is an infinite loop?

loopCount = 1; while(loopCount < 3); { System.out.println("Hello"); }

When mathematicians use a two-dimensional array, they often call it a ____.

matrix

You use a unary minus sign preceding a value to make the value ____.

negative

With ____ loops, the order of the conditional expressions can be important.

nested

If a class has only a default constructor, you must call the constructor using the keyword ____ for each declared array element.

new

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

null

When you declare an array name, no computer memory address is assigned to it. Instead, the array variable name has the special value ____, or Unicode value '\u0000'.

null

String oneStr = "Welcome Jim" String twoStr = "Welcome Joe" Given the lines of code above, which of the following regionMatches() expressions will result in a value of true?

oneStr.regionMatches(0, twoStr, 0, 7)

Regarding enumerations, the ____ method returns an integer that represents the constant's position in the list of constants; as with arrays, the first position is 0.

ordinal

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

parallel

The Arrays class ____ methods are a new feature in Java 8 that makes sorting more efficient when thousands or millions of objects need to be sorted.

parallelSort

Takes a String argument and returns its double value

parseDouble()

The ____ method takes a String argument and returns its double value.

parseDouble()

Individual array elements are ____ by value when a copy of the value is made and used within the receiving method.

passed

Providing values for all the elements in an array is called ____ the array.

populating

Assume that aName refers to Roger. What is returned by aName.compareTo("Robert");

positive number

When you want to increase a variable's value by exactly 1, use the ____.

prefix increment operator

Before entering a loop, the first input statement, or ____, is retrieved.

priming read

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

primitive

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

property

The method header of the equals() method within the String class is ____.

public boolean equals(String s)

When you perform a ____, you compare a value to the endpoints of numerical ranges to find the category in which a value belongs.

range match

A(n) ____ is a variable that holds a memory address.

reference

The ArrayList class ____ method removes an item from an ArrayList at a specified location.

remove

The ____ method allows you to replace all occurrences of some character within a String.

replaceCharacter()

After you create an array variable, you still need to ____ memory space.

reserve

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

runtime error

Comparing a variable to a list of values in an array is a process called ____ an array.

searching

To alter just one character in a StringBuilder, you can use the ____ method, which allows you to change a character at a specified position within a StringBuilder object.

setCharAt()

Change the length of a string in a StringBuilder object

setLength()

An array that you can picture as a column of values, and whose elements you can access using one subscript, is a ____ array.

single-dimensional

The ArrayList class ____ method returns the current ArrayList size.

size

The negative integer returned by the binarySearch() method when the value is not found is the negative equivalent of the array ____.

size

The Arrays class ____ method sorts the specified array into ascending order.

sort()

When you initialize parallel arrays, it is convenient to use ____ so that the values that correspond to each other visually align on the screen or printed page.

spacing

Consider the statement: int anInt = Integer.parseInt("649"); You can tell that parseInt() is a(n) ____ method because you use it with the class name and not with an object.

static

The ____ method and the startsWith() method each take a String argument and return true or false if a String object does or does not end or start with the specified argument, respectively.

strEnd()

A(n) ____ is an integer contained within square brackets that indicates one of an array's variables.

subscript

Takes two integer arguments: a start position and an end position

substring()

In a do...while loop, the loop will continue to execute until ____.

the loop control variable is false

The methods of the Character class that begin with ____ return a character that has been converted to the stated format.

to

Returns the lowercase equivalent of the argument

toLowerCase()

Regarding enumerations, the ____ method returns the name of the calling constant object.

toString

The ____ method converts any object to a String.

toString()

Which of the following describes a data type for which only appropriate behaviors are allowed?

type-safe

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

value

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

value

When you declare a variable of a basic, primitive type, such as int x = 10;, the memory address where x is located holds the ____.

value of 10

It is important that the loop control ____ be altered within the body of the loop.

variable

Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true.

while

Class or object that wraps around a simpler element

wrapper


Ensembles d'études connexes

Med-Surge Nursing Cardio Prep U ch 25

View Set

II.1/II.2 Use semicolons and commas to separate clauses

View Set