Analyze the following code. double sum = 0; |
The program compiles and runs fine. |
What is the number of iterations in the following loop: for (int i = 1; i < n; i++) { |
n – 1 |
Analyze the following statement: double sum = 0; |
The program compiles and runs fine. |
The elements inside the for loop control are separated using semicolons instead of commas. True/False |
True |
What is the value in count after the following loop is executed? int count = 0; |
10 |
What is the output of the following fragment? for (int i = 0; i < 15; i++) { |
1 5 9 13 |
What is y after the following for loop statement is executed? int y = 0; |
10 |
What is the output for y? int y = 0; |
45 |
A continue statement can be used only in a loop. True/False |
True |
A break statement can be used only in a loop. True/False |
False |
What is sum after the following loop terminates? int sum = 0; |
6 |
Which of the following loops produces the following output? (choose all that apply) 1 2 3 4 1 2 3 1 2 1 (I) (II)
(III) (IV) |
I & IV |
A variable declared in the for loop control can be used after the loop exits. True/False |
False |
What is i after the following for loop? int y = 0; |
Undefined |
Do the following two statements in (I) and (II) result in the same value in sum? (I): (II): |
Yes |
Is the following loop correct? for (; ; ); |
Yes |
You can always convert a for loop to a while loop. True/False |
True |
How many times will the following code print "Welcome to Java"? int count = 0; |
10 |
How many times are the following loops executed? for (int i = 0; i < 10; i++) |
45 |
Suppose cond1 is a Boolean expression. When will this while condition be true? while ( !cond1) … |
If cond1 is false |
Assume x is 0. What is the output of the following statement? if (x > 0) |
x = 0 |
What is the output of the following code: for ( ; false ; ) |
Does not print anything |
You can always convert a while loop to a for loop. |
True |
What is 1.0 + 1.0 + 1.0 == 3.0? |
There is no guarantee that 1.0 + 1.0 + 1.0 == 3.0 is true. |
How many times will the following code print "Welcome to Java"? int count = 0; |
10 |
Analyze the following fragment: double sum = 0; |
The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers. |
Which of the following expression yields an integer between 0 and 100, inclusive? |
(int)(Math.random() * 101) |
How many times will the following code print "Welcome to Java"? int count = 0; |
10 |
What is the value of balance after the following code is executed? int balance = 10; while (balance >= 1) { |
1 |
Analyze the following code. int count = 0; // Point C |
– count < 100 is always true at Point A – count < 100 is always false at Point C |
What balance after the following code is executed? int balance = 10; while (balance >= 1) { |
The loop does not end |
How many times will the following code print "Welcome to Java"? int count = 0; |
10 |
The while loop and the do loop are equivalent in their expressive power; in other words, you can rewrite a while loop using a do loop, and vice versa. True/False |
True |
What is the number of iterations in the following loop: for (int i = 1; i <= n; i++) { |
n |
How many times will the following code print "Welcome to Java"? int count = 0; |
11 |
You can always write a program without using break or continue in a loop. True/False |
True |
CS 4A- Chapter 5 – Loops
Share This
Unfinished tasks keep piling up?
Let us complete them for you. Quickly and professionally.
Check Price