csc 120 chapter 4 quiz

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

The increment operator is:

++

How many times will the following for loop be executed? 10 21

12

What will be the value of x after the following code is executed? 10 20 <

200

Which of the following will open a file named MyFile.txt and allow you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

You can use this method to determine whether a file exists.

The File class's exists method

In all but rare cases, loops must contain within themselves:

a way to terminate

This is an item that separates other items.

delimiter

In a for statement, the control variable can only be incremented.

false

The do- while loop is a pre-test loop.

false

________ is the process of inspecting data given to the program by the user and determining if it is valid.

input validation

A sentinel value ________ and signals that there are no more values to be entered.

is a special value that cannot be mistaken as a member of the list

In the following code, what values could be read into number to terminate the while loop?

the boolean condition can never be true

A file must always be opened before using it and closed when the program is finished using it.

true

When you open a file with the PrintWriter class, the class can potentially throw an IOException.

true

How many times will the following do-while loop be executed?

1

This type of loop is ideal in situations where the exact number of iterations is known.

for loop

When using the PrintWriter class, which of the following import statements would you write near the top of your program?

import java.io.*;

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()) { ... }

Each repetition of a loop is known as what?

an iteration

What will be the value of x after the following code is executed? int x, y = 15, z = 3; x = (y--) / (++z);

3

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

If a loop does not contain within itself a way to terminate, it is called a(n):

infinite loop

What will be the value of x after the following code is executed? >

infinite loop

This variable controls the number of times that the loop iterates.

loop control variable

This is a sum of numbers that accumulates with each iteration of a loop.

running total

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

You can use the PrintWriter class to open a file for writing and write data to 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--;

x = 17, y = 4

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

A loop that executes as long as a particular condition exists is called a(n):

conditional loop

A loop that repeats a specific number of times is known as a(n):

counter-controlled loop


Kaugnay na mga set ng pag-aaral

4. Financial statements and accounting

View Set

Chapter 34: The Immune System CONNECT

View Set

Physical Fitness : 3. CARDIOVASCULAR FITNESS

View Set

1,001 CCNA Questions: Chapter 18 Cisco IOS Fundamentals

View Set

Chapter 9: Healthy Relationships

View Set