Review Chapter 7

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

What will be the value of position after the following code is executed? int position; String str = "Thw cow jumped over the moon." position = str.lastIndexOf("ov",14);

15

What will be the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2014", "-", true);

9, 14, 2014, and -

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

A reference to the String "ghi"

What does the following statement do? double [] array1 = new double[10]

All of these

What will be the result of the following code? final int ARRAY_SIZE = 5; float[] x = float [ARRAY_SIZE]; for(int i=1; i<= ARRAY_SIZE; i++) { x[i] = 10.0; }

All the values in the array will be initialized to 10.0.

The following import statement is required to use the ArrayList class:

import java.util.ArrayList;

Which of the following import statements is required to use the StringTokenizer class?

import java.util.StringTokenizer;

A search algorithm

is used to locate a specific item in a larger collection of data.

The ________ class is the wrapper class for the char data type

Character

If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.

False

The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.

False

What will be displayed after the following code has been executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str2) System.out.println(matches);

False

When an array of objects is declared, but not initialized, the array values are set to 0.

False

You cannot assign a value to a wrapper class object.

False

What does <String> specify in the following statement? ArrayList<String>

It specifies that only String objects may be stored in the ArrayList object.

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9];

The numbers array has 6 rows and 9 columns.

int[] number = {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 sum of all the values in the numbers array.

A series of words or other items of data separated by spaces or other characters are known as

Tokens

Java does not limit the number of dimensions that an array may have.

True

Most of the String comparison methods are case sensitive.

True

The Java compiler does not display an error message when it processes a statement that uses an invalid subscript.

True

To determine if two arrays are equal, you must compare each of the elements of the two arrays.

True

You will cause an off-by-one error, when working with a character position within a string, if you think of the first position in a string as 1.

True

What will be displayed after the following code is executed? String str = "RSTUVWXYZ"; System.out.println(str.chatAt(5));

W

What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder("We have lived in Chicago, Trenton, and Atlanta.")

We have lived in Tampa, Trenton, and Atlanta.

If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

numbers[r].length

You can use the ________ method to replace an item at a specific location in an ArrayList.

set

You use this method to determine the number of items stored in an ArrayList object.

size

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

subscript

The Character wrapper class provides numerous methods for

testing and converting character data.

This method returns a string representing all of the items stored in an ArrayList object.

toString

You can concatenate String objects by

using the concat method or the + operator.

Java provides a mechanism known as ________, which makes it possible to write a method that takes a variable number of arguments.

variable-length argument lists

You can use this ArrayList class method to insert an item at a specific location in an ArrayList.

add

When an array is passed to a method

all of these

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command line.

true

The binary search algorithm

will cut the portion of the array being searched in half each it fails to locate the search value.

What will be the result of the following code?

The value variable will contain the sum of all the values in the numbers array.

In order to do a binary search on an array,

Must be an integar

Which of the following import statements is required to use the Character wrapper class?

No import statement is needed

Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

String str = Integer.toString(number);

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

True

Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.

True

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

True

StringBuilder objects are not immutable.

True

Trying to extract more tokens than exist from a StringTokenizer object will cause an error.

True

In the ________ file format, when the data in a spreadsheet is exported, each row is written to a line, and the values in the cells are separated by commas.

comma separated value

Which of the following is a valid declaration for a ragged array with five rows, but no columns?

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

String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20,26); System.out.println(str2);

jumped

What will be displayed after the following statements are executed? String str = "red$green&blue#orange"; String[] tokens = str.split("[$&#]"); for (String s : tokens ) System.out.print(s + " ");

red green blue orange

The String class's regionMatches method performs a case-insensitive comparison.

True


Kaugnay na mga set ng pag-aaral

BYU Writing 045 - Lesson 6 Speedback

View Set

nys real estate licensing study guide part 2

View Set

dump/how things work test review

View Set

Interventions 2 Exam 1 Modules 1-5

View Set

Module 1: Section C Fundamentals of sales and Operations Planning

View Set

Inquizitive: Integrating Sources

View Set

Hair care / types of conditioner

View Set