chapter 5 hava
A ________ is a value that signals when the end of a list of values has been reached.
sentinel
A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items from the list to be processed.
sentinel
What will be the value of x after the following code is executed? int x, y = 15; x = y--;
15
What will be the value of x after the following code is executed? int x = 10; for (int y = 5; y < 20; y +=5) x += y;
40
How many times will the following do-while loop be executed? int x = 11;
5
Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
The variable used to keep the running total is called a(n)
accumulator
Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt?
diskOut.println("Calvin");
The ________ loop is ideal in situations where you always want the loop to iterate at least once.
do-while
Before entering a loop to compute a running total, the program should first
set the accumulator variable to an initial value, usually zero;
In general, there are two types of files:
text and binary
What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++;
x =33, y = 9
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);
1
What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 10; }
100
How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("Java is great!");
12
In all but rare cases, loops must contain within themselves
a way to terminate
A for loop normally performs which of these steps?
all;update the control variable during each iteration, test the control variable by comparing it to a maximum/minimum value and terminate when it reaches that value
A loop that executes as long as a particular condition exists is called a(n) ________ loop
conditional
A loop that repeats a specific number of times is known as a(n) ________ loop
count controlled
The ________ is ideal in situations where the exact number of iterations is known
for loop
If a loop does not contain within itself a way to terminate, it is called
infinite loop
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an intfrom the file?
int number = inputFile.nextInt();
What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename);
it allows the user to enter the name of the file that data will to be written to
This type of loop will always be executed at least once.
post test
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())