Advertisement Upgrade to remove ads

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

Count-controlled loop

What will be the value of x after the following code is executed?
int x, y = 15;
x = y--;

15

This is a value that signals when the end of a list of values has been reached.

Sentinel

This type of loop will always be executed at least once.

Post-test loop

Which of the following are pre-test loops:

while, for

What will be the value of x after the following code is executed?
int x = 10;
while (x < 100)

100

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

Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboard.nextInt();
while (number < 100 && number > 500)
{
System.out.print("Enter another number: ");
number = keyboard.nextInt();
}

The boolean condition can never be true

How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);

1

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");
PrintWriter outFile = new PrintWriter(fwriter);
B) FileWriter fwriter = new FileWriter("MyFile.txt", true);
PrintWriter outFile = new PrintWriter(fwriter);
C) PrintWriter outfile = new PrintWriter("MyFile.txt", true);
D) PrintWriter outfile = new PrintWriter(true, "MyFile.txt");

B) FileWriter fwriter = new FileWriter("MyFile.txt", true);
PrintWriter outFile = new PrintWriter(fwriter);

What will be printed after the following code is executed?
for (int number = 5; number <= 15; number +=3)
System.out.print(number + ", ");

5, 8, 11, 14

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

for loop

What will be the value of x after the following code is executed?
int x = 10;
do
{
x *= 20;
} while (x < 5);

200

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

The File class's exists method

This is an item that separates other items.

Delimiter

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

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.next();
B) int number = inputFile.integer();
C) int number = inputFile.readInt();
D) int number = inputFile.nextInt();

D) int number = inputFile.nextInt();

If a loop does not contain within itself a way to terminate, it is called

An infinite loop

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

Conditional loop

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

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

Running total

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

int x = 10, y = 20;
while (y < 100)
{
x += y;
y += 20;
}

210

In the following code, what values could be read into number to terminate the while loop?
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboard.nextInt();
while (number < 100 || number > 500)
{
System.out.print("Enter another number: ");
number = keyboard.nextInt();
}

Numbers in the range 100 through 500

When you open a file with the PrintWriter class, the class can potentially throw an IOException
True or False

True

True or False
The do-while loop must be terminated with a semicolon.

True

True or False
In a for loop, the control variable can only be incremented.

False

True or False\
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

True or False

When you pass the name of a fi le 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

True or False
The do-while loop is a pre-test loop.

False

True or False

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

False

Please allow access to your computer’s microphone to use Voice Recording.

Having trouble? Click here for help.

We can’t access your microphone!

Click the icon above to update your browser permissions above and try again

Example:

Reload the page to try again!

Reload

Press Cmd-0 to reset your zoom

Press Ctrl-0 to reset your zoom

It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

Please upgrade Flash or install Chrome
to use Voice Recording.

For more help, see our troubleshooting page.

Your microphone is muted

For help fixing this issue, see this FAQ.

Star this term

You can study starred terms together

NEW! Voice Recording

Create Set