Deck 4: Control Structures I: Selection

Full screen (f)
exit full mode
Question
Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y is true.
Use Space or
up arrow
down arrow
to flip the card.
Question
=! is a relational operator.
Question
In Java, !, &&, and || are called logical operators.
Question
Suppose P and Q are logical expressions. The logical expression P && Q is false if both P and Q are false.
Question
The expression 'A' 'B' evaluates to false while the expression 'A' 'B' evaluates to true.
Question
All switch cases include a break statement.
Question
When one control statement is located within another, it is said to be a controlled statement.
Question
Including a semicolon before the action statement in a one-way selection causes a syntax error.
Question
The symbol >= is a logical operator.
Question
In Java, case and switch are reserved words, but break is not a reserved word.
Question
A computer program will recognize both = and == as the equality operator.
Question
All switch structures include default cases.
Question
The expression !(x is true only if x is a positive number.
Question
Suppose that the input is 6 and console is a Scanner object initialized to the standard input device. Consider the following code.int alpha = 7;
int beta = console.nextInt();switch (beta)
{
case 5:
alpha = alpha + 1;
case 6:
alpha = alpha + 2;
case 7:
alpha = alpha + 3;
default:
alpha = alpha + 5;
}System.out.print(alpha);The output of this code is 9.
Question
A program uses selection to implement a branch.
Question
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
Question
Suppose that you have the following code.int num = 10;if (num > 10)
System.out.println(num);
else
System.out.println(num + 5);The output of this code is 5.
Question
Suppose that you have the following statements.int score;
String grade;if (score >= 65)
grade = "pass";
else
grade = "fail";If score is equal to 75, the value of grade is pass.
Question
The operators = and == have the same order of precedence.
Question
In Java, || has a higher precedence than &&.
Question
What is the output of the following Java code?int x = 0;
If (x > 0)
System.out.println("positive ");
System.out.println("zero ");
System.out.println("negative");

A) zero
B) negative
C) zero negative
D) positive zero negative
Question
Which of the following has the highest value?

A) '-'
B) '5'
C) 'H'
D) 'b'
Question
'A' = 7 || 4 Based on the code above, which part of the expression is not evaluated?

A) 2.5 >= 7
B) 4
C) 2.5 >= 7 || 4
D) 4
Question
Which of the following will cause a syntax error, if you are trying to compare x to 5?

A) if (x == 5)
B) if (x = 5)
C) if (x<= 5)
D) if (x >= 5)
Question
In a ____ control structure, the computer executes particular statements depending on some condition(s).

A) looping
B) repetition
C) selection
D) sequence
Question
Two-way selection in Java is implemented using ____.

A) if statements
B) for loops
C) if...else statements
D) sequential statements
Question
Which of the following is NOT a relational operator in Java?

A)< >
B)<
C) ==
D) >
Question
The method compareTo is part of the class String.
Question
What does >= mean?

A) less than
B) greater than
C) less than or equal to
D) greater than or equal to
Question
Suppose that x is an int variable. Which of the following expressions always evaluates to false?

A) (x > 0) || (x<=0)
B) (x > 0) || (x == 0)
C) (x > 0) && ( x<=0)
D) (x >= 0) && (x == 0)
Question
Which of the following is a relational operator?

A) =
B) ==
C) !
D) &&
Question
Suppose that you have the following statements.String str1 = "cat";
String str2 = "cats";The statement str1.equals(str2); is true.
Question
The execution of a break statement in a switch statement terminates the switch statement.
Question
Which of the following is not a logical operator?

A) !
B) ||
C) !=
D) &&
Question
Which of the following will cause a syntax error?

A) (10 < num) && (num < 30)
B) 10 < num <20
C) 10 < num && num < 25
D) num > 10 && num<40
Question
Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1 and str2 point to the same String object.
Question
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 4?

A) 2
B) 4
C) 6
D) 8
Question
The output of the Java code:int alpha = 5;
int beta = 4;switch (beta)
{
case 2:
alpha = alpha + 2;
case 4:
alpha = alpha + 4;
break;
case 6:
alpha = alpha + 6;
default:
alpha = alpha + 10;
}
System.out.print(alpha);is: 9
Question
After the execution of the following code, what will be the value of num if the input values are 0 3? (Assume that console is a Scanner object initialized to the standard input device.)int num = console.nextInt();if (num > 0)
Num = num + 13;
Else
If (num >= 3)
Num = num + 15;

A) 0
B) 3
C) 13
D) 15
Question
'A' = 7 || 4 What is the value of the expression above?

A) true
B) false
C) x
D) It cannot be determined.
Question
int x;
X = (1 'K' >= 'F') ? 5 : 12Based on the code above, what is the value of x?

A) 1
B) 3
C) 5
D) 12
Question
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 9?

A) 2
B) 4
C) 6
D) 8
Question
The conditional operator ?: takes ____ arguments.

A) two
B) three
C) four
D) five
Question
switch (lastInitial)
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'E'?

A) section 2
B) section 3
C) section 4
D) section 5
Question
Suppose that you have the following code:int sum = 0;
Int num = 8;if (num 5)
Sum = num + 15;After this code executes, what is the value of sum?

A) 0
B) 8
C) 15
D) 23
Question
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 5?

A) 2
B) 4
C) 6
D) 8
Question
switch (lastInitial)
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'C'?

A) section 1
B) section 2
C) section 3
D) section 5
Question
If str1 is "Hello" and str2 is "Hi", which of the following could not be a result of str1.compareTo(str2);?

A) -9
B) -5
C) -1
D) 1
Question
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 1?

A) 2
B) 4
C) 6
D) 8
Question
What is the output of the following Java code?int x = 57;
Int y = 3;switch (x % 9)
{
Case 0:
Case 1:
Y++;
Case 2:
Y = y - 2;
Break;
Case 3:
Y = y + 2;
Case 4:
Break;
Case 5:
Case 6:
Y = y + 3;
}System.out.println(y);

A) 2
B) 5
C) 6
D) 57
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Control Structures I: Selection
1
Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y is true.
True
2
=! is a relational operator.
False
3
In Java, !, &&, and || are called logical operators.
True
4
Suppose P and Q are logical expressions. The logical expression P && Q is false if both P and Q are false.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The expression 'A' 'B' evaluates to false while the expression 'A' 'B' evaluates to true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
All switch cases include a break statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
When one control statement is located within another, it is said to be a controlled statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Including a semicolon before the action statement in a one-way selection causes a syntax error.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
The symbol >= is a logical operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
In Java, case and switch are reserved words, but break is not a reserved word.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
A computer program will recognize both = and == as the equality operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
All switch structures include default cases.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The expression !(x is true only if x is a positive number.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Suppose that the input is 6 and console is a Scanner object initialized to the standard input device. Consider the following code.int alpha = 7;
int beta = console.nextInt();switch (beta)
{
case 5:
alpha = alpha + 1;
case 6:
alpha = alpha + 2;
case 7:
alpha = alpha + 3;
default:
alpha = alpha + 5;
}System.out.print(alpha);The output of this code is 9.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
A program uses selection to implement a branch.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
Suppose that you have the following code.int num = 10;if (num > 10)
System.out.println(num);
else
System.out.println(num + 5);The output of this code is 5.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Suppose that you have the following statements.int score;
String grade;if (score >= 65)
grade = "pass";
else
grade = "fail";If score is equal to 75, the value of grade is pass.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The operators = and == have the same order of precedence.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
In Java, || has a higher precedence than &&.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
What is the output of the following Java code?int x = 0;
If (x > 0)
System.out.println("positive ");
System.out.println("zero ");
System.out.println("negative");

A) zero
B) negative
C) zero negative
D) positive zero negative
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following has the highest value?

A) '-'
B) '5'
C) 'H'
D) 'b'
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
'A' = 7 || 4 Based on the code above, which part of the expression is not evaluated?

A) 2.5 >= 7
B) 4
C) 2.5 >= 7 || 4
D) 4
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following will cause a syntax error, if you are trying to compare x to 5?

A) if (x == 5)
B) if (x = 5)
C) if (x<= 5)
D) if (x >= 5)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
In a ____ control structure, the computer executes particular statements depending on some condition(s).

A) looping
B) repetition
C) selection
D) sequence
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
Two-way selection in Java is implemented using ____.

A) if statements
B) for loops
C) if...else statements
D) sequential statements
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is NOT a relational operator in Java?

A)< >
B)<
C) ==
D) >
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
The method compareTo is part of the class String.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
What does >= mean?

A) less than
B) greater than
C) less than or equal to
D) greater than or equal to
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Suppose that x is an int variable. Which of the following expressions always evaluates to false?

A) (x > 0) || (x<=0)
B) (x > 0) || (x == 0)
C) (x > 0) && ( x<=0)
D) (x >= 0) && (x == 0)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is a relational operator?

A) =
B) ==
C) !
D) &&
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Suppose that you have the following statements.String str1 = "cat";
String str2 = "cats";The statement str1.equals(str2); is true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
The execution of a break statement in a switch statement terminates the switch statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following is not a logical operator?

A) !
B) ||
C) !=
D) &&
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following will cause a syntax error?

A) (10 < num) && (num < 30)
B) 10 < num <20
C) 10 < num && num < 25
D) num > 10 && num<40
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1 and str2 point to the same String object.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 4?

A) 2
B) 4
C) 6
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
The output of the Java code:int alpha = 5;
int beta = 4;switch (beta)
{
case 2:
alpha = alpha + 2;
case 4:
alpha = alpha + 4;
break;
case 6:
alpha = alpha + 6;
default:
alpha = alpha + 10;
}
System.out.print(alpha);is: 9
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
After the execution of the following code, what will be the value of num if the input values are 0 3? (Assume that console is a Scanner object initialized to the standard input device.)int num = console.nextInt();if (num > 0)
Num = num + 13;
Else
If (num >= 3)
Num = num + 15;

A) 0
B) 3
C) 13
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
'A' = 7 || 4 What is the value of the expression above?

A) true
B) false
C) x
D) It cannot be determined.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
int x;
X = (1 'K' >= 'F') ? 5 : 12Based on the code above, what is the value of x?

A) 1
B) 3
C) 5
D) 12
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 9?

A) 2
B) 4
C) 6
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
The conditional operator ?: takes ____ arguments.

A) two
B) three
C) four
D) five
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
switch (lastInitial)
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'E'?

A) section 2
B) section 3
C) section 4
D) section 5
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Suppose that you have the following code:int sum = 0;
Int num = 8;if (num 5)
Sum = num + 15;After this code executes, what is the value of sum?

A) 0
B) 8
C) 15
D) 23
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 5?

A) 2
B) 4
C) 6
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
switch (lastInitial)
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'C'?

A) section 1
B) section 2
C) section 3
D) section 5
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
If str1 is "Hello" and str2 is "Hi", which of the following could not be a result of str1.compareTo(str2);?

A) -9
B) -5
C) -1
D) 1
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 1?

A) 2
B) 4
C) 6
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
What is the output of the following Java code?int x = 57;
Int y = 3;switch (x % 9)
{
Case 0:
Case 1:
Y++;
Case 2:
Y = y - 2;
Break;
Case 3:
Y = y + 2;
Case 4:
Break;
Case 5:
Case 6:
Y = y + 3;
}System.out.println(y);

A) 2
B) 5
C) 6
D) 57
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.