In a for loop, the control variable can only be incremented.
==true..
Before entering a loop to compute a running total, the program should first
==Set the accumulator where the total will be kept to an initial value, usually zero
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
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
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.
==false
A loop that repeats a specific number of times is known as a(n) ________.
==Counter-controlled loop
This is a sum of numbers that accumulates with each iteration of a loop
==Running total
This is an item that separates other items.
==Delimiter
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
==true
If a loop does not contain within itself a way to terminate, it is called
==An infinite loop
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?
==int number = inputFile.nextInt();*****
A loop that executes as long as a particular condition exists is called a(n) ________.
==Conditional loop
A for loop normally performs which of these steps?
==All of the above**
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
The do-while loop is a pre-test loop.
==false
The do-while loop must be terminated with a semicolon.
==true
Look at the following code:
Scanner keyboard = new Scanner(System.in);
int studentGrade = 0;
int totalOfStudentGrades = 0;
while(studentGrade != -1)
{
System.out.println("Enter student grade: :");
studentGrade = keyboard.nextInt();
totalOfStudentGrades += studentGrade;
}
In the loop header: while(studentGrade != -1), what is the purpose of "-1"
====It is a sentinel
This is a value that signals when the end of a list of values has been reached.
==Sentinel
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
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x <= 100);
===5
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
What will be the value of x after the following code is executed?
int x = 10, y = 20;
while (y < 100)
{
x += y;
}
==This is an infinite loop
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
==1
This type of loop is ideal in situations where the exact number of iterations is known.
==for loop
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);
No comments:
Post a Comment