Deck 4: Control Statements

ملء الشاشة (f)
exit full mode
سؤال
Which of the following statements about a do…while repetition statement is true?

A) The body of a do…while loop is executed only if the terminating condition is true.
B) The body of a do…while loop is executed only once.
C) The body of a do…while loop is always executed at least once.
D) None of the above.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Which of the following can be used in a switch statement in the expression after keyword case?
A) a constant integral expression.
B) a character constant.
C) a String
D) an enumeration constant.

A) A and B.
B) A and C.
C) B and C.
D) All.
سؤال
Which statement prints the floating-point value 123.456 right justified with a field width of 10?

A) System.out.printf("%d10.3", 123.456);
B) System.out.printf("%10.3d", 123.456);
C) System.out.printf("%f10.3", 123.456);
D) System.out.printf("%10.3f", 123.456);
سؤال
Consider the classes below:
Public class TestA
{
Public static void main(String args[])
{
Int x = 2;
Int y = 20
Int counter = 0;
For (int j = y % x; j < 100; j += (y / x))
Counter++;
}
}
Public class TestB
{
Public static void main(String args[])
{
Int counter = 0;
For (int j = 10; j > 0; --j)
++counter;
}
}
Which of the following statements is true?

A) The value of counter will be different at the end of each for loop for each class.
B) The value of j will be the same for each loop for all iterations
C) Both (a) and (b) are true.
D) Neither (a) nor (b) is true.
سؤال
Consider the following two Java code segments:
Segment 1 Segment 2
Int i = 0;
For (int i = 0; i <= 20; i++)
While (i < 20) {
{ System.out.println(i);
I++; }
System.out.println(i);
}
Which of the following statements are true?

A) The output from these segments is not the same.
B) The scope of the control variable i is different for the two segments.
C) Both (a) and (b) are true.
D) Neither (a) nor (b) is true.
سؤال
Which of the following is equivalent to this code segment?
Int total = 0;
For (int i = 0; i <= 20; i += 2)
Total += i;

A) int total = 0; for (int i = 20; i < 0; i += 1)
Total += i;
B) int total = 0; for (int i = 0; i <= 20; total += i, i += 2);
C) int total = 0; for (int i = 0, i <= 20, total += i; i += 2);
D) int total = 0; for (int i = 2; i < 20; total += i, i += 2);
سؤال
The control variable of a counter-controlled loop should be declared as ________to prevent errors.

A) int
B) float
C) double
D) Any of the above.
سؤال
Consider the code segment below.
If (gender == 1)
{
If (age >= 65)
++seniorFemales;
}
This segment is equivalent to which of the following?

A) if (gender == 1 || age >= 65) ++seniorFemales;
B) if (gender == 1 && age >= 65) ++seniorFemales;
C) if (gender == 1 AND age >= 65) ++seniorFemales;
D) if (gender == 1 OR age >= 65) ++seniorFemales;
سؤال
Which of the following will not help prevent infinite loops?

A) Include braces around the statements in a do…while statement.
B) Ensure that the header of a for or while statement is not followed by a semicolon.
C) If the loop is counter-controlled, the body of the loop should increment or decrement the counter as needed.
D) If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.
سؤال
Suppose variable gender contains MALE and age equals 60, how is the expression
(gender == FEMALE) && (age >= 65)
Evaluated?

A) The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
B) The condition (age >= 65) is evaluated first and the evaluation stops immediately.
C) Both conditions are evaluated, from left to right.
D) Both conditions are evaluated, from right to left.
سؤال
Which of the following for-loop headers results in equivalent numbers of iterations:
A) for (int q = 1; q <= 100; q++)
B) for (int q = 100; q >= 0; q--)
C) for (int q = 99; q > 0; q -= 9)
D) for (int q = 990; q > 0; q -= 90)

A) A and B.
B) C and D.
C) A and B have equivalent iterations and C and D have equivalent iterations.
D) None of the loops have equivalent iterations.
سؤال
For the two code segments below:
Segment A
Int q = 5;
Switch(q)
{
Case 1:
System.out.println(1);
Case 2:
System.out.println(2);
Case 3:
System.out.println(3);
Case 4:
System.out.println(4);
Case 5:
System.out.println(5);
Default:
System.out.println("default");
}
Segment B
Q = 4;
Switch(q)
{
Case 1:
System.out.println(1);
Case 2:
System.out.println(2);
Case 3:
System.out.println(3);
Case 4:
System.out.println(4);
Case 5:
System.out.println(5);
Default:
System.out.println("default");
}
Which of the following statements is true?

A) The output for Segment A is: default
B) The output for Segment B is: 4
C) The output for Segment B is: 45default
D) The output for Segment A is: 5
Default
سؤال
Which of the following statements about the continue statement is true?

A) The continue statement is used to exit a repetition structure early and continue execution after the loop.
B) The continue statement is used to continue after a switch statement.
C) The continue statement does not alter the flow of control.
D) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do…while statement.
سؤال
Which of the following will count down from 10 to 1 correctly?

A) for (int j = 10; j <= 1; j++)
B) for (int j = 1; j <= 10; j++)
C) for (int j = 10; j > 1; j--)
D) for (int j = 10; j >= 1; j--)
سؤال
Which formatting flag indicates that the floating-point values should be output with a thousands separator?

A) plus (+).
B) minus (-).
C) comma (,).
D) period (.).
سؤال
For the code segment below:
Switch(q)
{
Case 1:
System.out.println("apple");
Break;
Case 2:
System.out.println("orange");
Break;
Case 3:
System.out.println("banana");
Break;
Case 4:
System.out.println("pear");
Case 5:
System.out.println("grapes");
Default:
System.out.println("kiwi");
}
Which of the following values for q will result in kiwi being included in the output?

A) 2.
B) Any integer less than 1 and greater than or equal to 4.
C) 1.
D) 3.
سؤال
Which of the following statements about the break statement is false?

A) The break statement is used to exit a repetition structure early and continue execution after the loop.
B) A break statement can only break out of an immediately enclosing while, for, do…while or switch statement.
C) The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
D) Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.
سؤال
Counter-controlled repetition requires

A) A control variable and initial value.
B) A control variable increment (or decrement).
C) A condition that tests for the final value of the control variable.
D) All of the above.
سؤال
To exit out of a loop completely, and resume the flow of control at the next statement after the loop, use a _______.

A) continue statement.
B) break statement.
C) return statement.
D) Any of the above.
سؤال
Which of the following statements about the switch statement is false?

A) You can use Strings in a switch statement's controlling expression.
B) You can use a String in a switch statement's case label.
C) You can use a comma-separated list of Strings in a switch statement's case label.
D) You cannot use a String in a switch statement's default case label.
سؤال
Which expression is equivalent to if (!(grade == sentinelValue))?

A) if (grade !== sentinelValue)
B) if (grade != sentinelValue)
C) ! if (grade == sentinelValue)
D) ! if (grade !== sentinelValue)
سؤال
Which statement below is false?

A) Structured programming produces programs that are easier to test.
B) Structured programming requires four forms of control.
C) Structured programming produces programs that are easier to modify
D) Structured programming promotes simplicity.
سؤال
Boolean values can be displayed as the words true and false with the ________ format specifier.

A) %bool.
B) %b.
C) %true.
D) %boolean.
سؤال
Which case of the following would warrant using the boolean logical inclusive OR (|) rather than the conditional OR (||)?

A) Testing if two conditions are both true.
B) Testing if at least one of two conditions is true.
C) Testing if at least one of two conditions is true when the right operand has a required side effect.
D) Testing if at least one of two conditions is true when the left operand has a required side effect.
سؤال
Method drawOval's arguments specify ________.

A) the upper-left and upper-right corners of the oval.
B) the upper-left corner, scale and size of the oval.
C) the position and size of the bounding rectangle for the oval.
D) the position and size of the bounding cycle for the oval.
سؤال
The first statement in every paintComponent method should be a call to ________.

A) super
B) super.paintComponent
C) clear
D) update
سؤال
Which of the following is not a type of repetition statement in Java?

A) while statement.
B) do…while statement.
C) for statement.
D) loop statement.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/27
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 4: Control Statements
1
Which of the following statements about a do…while repetition statement is true?

A) The body of a do…while loop is executed only if the terminating condition is true.
B) The body of a do…while loop is executed only once.
C) The body of a do…while loop is always executed at least once.
D) None of the above.
C
2
Which of the following can be used in a switch statement in the expression after keyword case?
A) a constant integral expression.
B) a character constant.
C) a String
D) an enumeration constant.

A) A and B.
B) A and C.
C) B and C.
D) All.
D
3
Which statement prints the floating-point value 123.456 right justified with a field width of 10?

A) System.out.printf("%d10.3", 123.456);
B) System.out.printf("%10.3d", 123.456);
C) System.out.printf("%f10.3", 123.456);
D) System.out.printf("%10.3f", 123.456);
D
4
Consider the classes below:
Public class TestA
{
Public static void main(String args[])
{
Int x = 2;
Int y = 20
Int counter = 0;
For (int j = y % x; j < 100; j += (y / x))
Counter++;
}
}
Public class TestB
{
Public static void main(String args[])
{
Int counter = 0;
For (int j = 10; j > 0; --j)
++counter;
}
}
Which of the following statements is true?

A) The value of counter will be different at the end of each for loop for each class.
B) The value of j will be the same for each loop for all iterations
C) Both (a) and (b) are true.
D) Neither (a) nor (b) is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
5
Consider the following two Java code segments:
Segment 1 Segment 2
Int i = 0;
For (int i = 0; i <= 20; i++)
While (i < 20) {
{ System.out.println(i);
I++; }
System.out.println(i);
}
Which of the following statements are true?

A) The output from these segments is not the same.
B) The scope of the control variable i is different for the two segments.
C) Both (a) and (b) are true.
D) Neither (a) nor (b) is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
6
Which of the following is equivalent to this code segment?
Int total = 0;
For (int i = 0; i <= 20; i += 2)
Total += i;

A) int total = 0; for (int i = 20; i < 0; i += 1)
Total += i;
B) int total = 0; for (int i = 0; i <= 20; total += i, i += 2);
C) int total = 0; for (int i = 0, i <= 20, total += i; i += 2);
D) int total = 0; for (int i = 2; i < 20; total += i, i += 2);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
7
The control variable of a counter-controlled loop should be declared as ________to prevent errors.

A) int
B) float
C) double
D) Any of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
8
Consider the code segment below.
If (gender == 1)
{
If (age >= 65)
++seniorFemales;
}
This segment is equivalent to which of the following?

A) if (gender == 1 || age >= 65) ++seniorFemales;
B) if (gender == 1 && age >= 65) ++seniorFemales;
C) if (gender == 1 AND age >= 65) ++seniorFemales;
D) if (gender == 1 OR age >= 65) ++seniorFemales;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
9
Which of the following will not help prevent infinite loops?

A) Include braces around the statements in a do…while statement.
B) Ensure that the header of a for or while statement is not followed by a semicolon.
C) If the loop is counter-controlled, the body of the loop should increment or decrement the counter as needed.
D) If the loop is sentinel-controlled, ensure that the sentinel value is input eventually.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
10
Suppose variable gender contains MALE and age equals 60, how is the expression
(gender == FEMALE) && (age >= 65)
Evaluated?

A) The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
B) The condition (age >= 65) is evaluated first and the evaluation stops immediately.
C) Both conditions are evaluated, from left to right.
D) Both conditions are evaluated, from right to left.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following for-loop headers results in equivalent numbers of iterations:
A) for (int q = 1; q <= 100; q++)
B) for (int q = 100; q >= 0; q--)
C) for (int q = 99; q > 0; q -= 9)
D) for (int q = 990; q > 0; q -= 90)

A) A and B.
B) C and D.
C) A and B have equivalent iterations and C and D have equivalent iterations.
D) None of the loops have equivalent iterations.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
12
For the two code segments below:
Segment A
Int q = 5;
Switch(q)
{
Case 1:
System.out.println(1);
Case 2:
System.out.println(2);
Case 3:
System.out.println(3);
Case 4:
System.out.println(4);
Case 5:
System.out.println(5);
Default:
System.out.println("default");
}
Segment B
Q = 4;
Switch(q)
{
Case 1:
System.out.println(1);
Case 2:
System.out.println(2);
Case 3:
System.out.println(3);
Case 4:
System.out.println(4);
Case 5:
System.out.println(5);
Default:
System.out.println("default");
}
Which of the following statements is true?

A) The output for Segment A is: default
B) The output for Segment B is: 4
C) The output for Segment B is: 45default
D) The output for Segment A is: 5
Default
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following statements about the continue statement is true?

A) The continue statement is used to exit a repetition structure early and continue execution after the loop.
B) The continue statement is used to continue after a switch statement.
C) The continue statement does not alter the flow of control.
D) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do…while statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
14
Which of the following will count down from 10 to 1 correctly?

A) for (int j = 10; j <= 1; j++)
B) for (int j = 1; j <= 10; j++)
C) for (int j = 10; j > 1; j--)
D) for (int j = 10; j >= 1; j--)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which formatting flag indicates that the floating-point values should be output with a thousands separator?

A) plus (+).
B) minus (-).
C) comma (,).
D) period (.).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
16
For the code segment below:
Switch(q)
{
Case 1:
System.out.println("apple");
Break;
Case 2:
System.out.println("orange");
Break;
Case 3:
System.out.println("banana");
Break;
Case 4:
System.out.println("pear");
Case 5:
System.out.println("grapes");
Default:
System.out.println("kiwi");
}
Which of the following values for q will result in kiwi being included in the output?

A) 2.
B) Any integer less than 1 and greater than or equal to 4.
C) 1.
D) 3.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the following statements about the break statement is false?

A) The break statement is used to exit a repetition structure early and continue execution after the loop.
B) A break statement can only break out of an immediately enclosing while, for, do…while or switch statement.
C) The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
D) Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
18
Counter-controlled repetition requires

A) A control variable and initial value.
B) A control variable increment (or decrement).
C) A condition that tests for the final value of the control variable.
D) All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
19
To exit out of a loop completely, and resume the flow of control at the next statement after the loop, use a _______.

A) continue statement.
B) break statement.
C) return statement.
D) Any of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following statements about the switch statement is false?

A) You can use Strings in a switch statement's controlling expression.
B) You can use a String in a switch statement's case label.
C) You can use a comma-separated list of Strings in a switch statement's case label.
D) You cannot use a String in a switch statement's default case label.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which expression is equivalent to if (!(grade == sentinelValue))?

A) if (grade !== sentinelValue)
B) if (grade != sentinelValue)
C) ! if (grade == sentinelValue)
D) ! if (grade !== sentinelValue)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
22
Which statement below is false?

A) Structured programming produces programs that are easier to test.
B) Structured programming requires four forms of control.
C) Structured programming produces programs that are easier to modify
D) Structured programming promotes simplicity.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
23
Boolean values can be displayed as the words true and false with the ________ format specifier.

A) %bool.
B) %b.
C) %true.
D) %boolean.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
24
Which case of the following would warrant using the boolean logical inclusive OR (|) rather than the conditional OR (||)?

A) Testing if two conditions are both true.
B) Testing if at least one of two conditions is true.
C) Testing if at least one of two conditions is true when the right operand has a required side effect.
D) Testing if at least one of two conditions is true when the left operand has a required side effect.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
25
Method drawOval's arguments specify ________.

A) the upper-left and upper-right corners of the oval.
B) the upper-left corner, scale and size of the oval.
C) the position and size of the bounding rectangle for the oval.
D) the position and size of the bounding cycle for the oval.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
26
The first statement in every paintComponent method should be a call to ________.

A) super
B) super.paintComponent
C) clear
D) update
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
27
Which of the following is not a type of repetition statement in Java?

A) while statement.
B) do…while statement.
C) for statement.
D) loop statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 27 في هذه المجموعة.