chapter 4
You can use this method to determine whether a file exists.
. B) The File class's exists method
What will be the value of x after the following code is executed? int x, y = 15, z = 3; x = (y--) / (++z);
A) 3
each repetition of a loop is known as what?
A) an iteration
If you are using block of statements, don't forget to enclose all of the statements in a set of
A) braces
a loop that executes as long as a particular condition exists is called an
B) conditional loop
This type of loop is ideal in situations where you always want the loop to iterate at least once
B) do-while loop
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
False
A file must always be opened before using it and closed when the program is finished using it
True
What will be the values of x and y as a result of the following code? int x = 12, y = 5; x += y--;
d. x = 17, y = 4
Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?
A)FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);
A sentinel value_____ and signals that there are no more values to be entered
B) is a special value that cannot be mistaken as a member of the list
when using the print writer class which of the following import statements would you write near the top of your program?
B) java.io
This variable controls the number of times that the loop iterates
B) loop control variable
Before entering a loop to compute a running total, the program should first do this.
B) set the accumulator where the total will be kept to an initial value, usually zero
This type of loop will always be executed at least once
B)post test loop
In all but rare cases, loops must contain within themselves
C) a way to terminate
A loop that repeats a specific number of times is known as a
C) counter controlled loop
This type of loop is ideal in situations where the exact number of iterations is known.
C) for loop
This type of loop allows the user to decide the number o iterations
C) user controlled loop
Which of the following are pre-test loops?
C) while, for
A for loop normally performs which of these steps?
D) all of the above
This is an item that separates other items.
D) delimiter
This is a value that signals when the end of a list of values has been reached
D)sentinel
In a for statement, the control variable can only be incremented
False
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value
False
The do-while loop is a pretest loop
False
The do-while loop must be terminated with a semicolon
True
The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true
True
When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
True
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
True
You can use the PrintWriter class to open a file for writing and write data to it
True
If a loop does not contain within itself a way to terminate, it is called a
d) infinite loop
When you pass the name of a file to the PrintWriter constructor, and the file already exists, it will be erased and a new empty file with the same name will be created
true
Java provides a set of simple unary operators designed just for incrementing and decrementing variables
True
This is a sum of number s that accumulates with each iteration of a loop.
A) running total
______ is the process of inspecting data given to the program by the user and determining if it is valid
B) input validation
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?
while (inputFile.hasNext()) { ... }