Chapter 4
The increment operator is: A) ++ B) -- C) *= D) -=
A) ++
Each repetition of a loop is known as what? A) An iteration B) A cycle C) An execution D) A Lap
A) An iteration
If you are using a block of statements, don't forget to enclose all of the statements in a set of: A) Braces B) Double quotes C) Semicolons D) Parentheses
A) Braces
This is a sum of numbers that accumulates with each iteration of a loop. A) Running total B) Final total C) Grand finale D) Galloping total
A) Running total
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file? A) int number = inputFile.nextInt(); B) int number = inputFile.next(); C) int number = inputFile.readInt(); D) int number = inputFile.integer();
A) int number = inputFile.nextInt();
What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 10; } A) 90 B) 100 C) 110 D) This is an infinite loop.
B) 100
What will be the value of x after the following code is executed? int x, y = 4, z = 6; x = (y++) * (++z); A) 24 B) 28 C) 30 D) 35
B) 28
This is a control structure that causes a statement or group of statements to repeat. A) Block B) Loop C) Prefix mode D) Body
B) Loop
This variable controls the number of times that the loop iterates. A) Counter variable B) Loop control variable C) Running total D) Decrement variable
B) Loop control variable
You can use this method to determine whether a file exists. A) The Scanner class's exists method B) The File class's exists method C) The File class's canOpen method D) The PrintWriter class's fileExists method
B) The File class's exists method
A loop that executes as long as a particular condition exists is called a(n): A) sentinel loop B) conditional loop C) count-controlled loop D) infinite loop
B) conditional loop
This type of loop is ideal in situations where you always want the loop to iterate at least once. A) while loop B) do-while loop C) for loop D) if statement
B) do-while loop
A sentinel value ________ and signals that there are no more values to be entered. A) is a different data type than the values being processed B) is a special value that cannot be mistaken as a member of the list C) indicates the start of a list D) guards the list
B) is a special value that cannot be mistaken as a member of the list
This type of loop will always be executed at least once. A) pre-test loop B) post-test loop C) sentinel loop D) for loop
B) post-test loop
What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3) System.out.print(number + ", "); A) 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, B) 5, 8, 11, 14, 17, C) 5, 8, 11, 14, D) This is an invalid for statement.
C) 5, 8, 11, 14,
Which of the following will open a file named MyFile.txt and allow you to read data from it? A) File file = new File("MyFile.txt"); B) Scanner inputFile = new Scanner("MyFile.txt"); C) File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); D) PrintWriter inputFile = new PrintWriter("MyFile.txt");
C) File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++; A) x = 25, y = 8 B) x = 33, y = 8 C) x = 33, y = 9 D) x = 34, y = 9
C) x = 33, y = 9
This is an item that separates other items. A) Controller B) Partition C) Doorway D) Delimiter
D) Delimiter
A for loop normally performs which of these steps? A) initializes a control variable to a starting value B) tests the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value C) updates the control variable during each iteration D) all of the above E) none of the above
D) all of the above
If a loop does not contain within itself a way to terminate, it is called a(n): A) while loop B) do-while loop C) for loop D) infinite loop
D) infinite loop