Chapter 5 Hava

25 July 2022
4.7 (114 reviews)
26 test answers

Unlock all answers in this set

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