
CP - Decision Control Structures
Quiz by Julliane
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
What are Decision Control Structures in Java programming?
Which statement is used when we want to execute a certain code block only if a certain condition is true?
What is the correct syntax for an if-else statement?
In an if-else statement, what happens if the condition is false?
What is the purpose of nesting if-else blocks?
Determine what type of decision control structure statement does the following flowcharts indicates

Determine what type of decision control structure statement does the following flowcharts indicates

Determine what type of decision control structure statement does the following flowcharts indicates

How is the syntax of a basic if-statement in Java?
In Java, what should the expression part of an if-statement evaluate to?
What is the purpose of indenting statements inside the if-block?
Which keyword is used to introduce an else block in an if-else statement?
The if-else statement in Java is used when you want to execute a block of code only if a condition is true.
To avoid confusion, it is recommended to always place the statements of an if or if-else block inside brackets.
Nested if-else blocks are not allowed in Java.
The else-if statement in Java can be used to create more complex decision-making structures
In an if-else-if statement, if a condition is true, the program executes the corresponding block and then moves to the next else-if block.
It is recommended to use ____________ to group statements inside the if or if-else block.
Fill in the blanks
The ____________ part of an if statement should evaluate to a boolean value.
The else-clause in an if-else statement can contain another ____________ block.
The else-if statement allows us to have ____________ conditions to choose from.
The if-else statement is used when we want to execute one block of code if a condition is true and another block if the condition is ____________.
Match the code snippets with the correct control structure:
if (grade > 60) { System.out.println("Congratulations!"); }
Match the code snippets with the correct control structure:
if (grade > 60) { System.out.println("Congratulations!"); } else { System.out.println("Sorry you failed"); }
Match the code snippets with the correct control structure:
if (grade > 90) { System.out.println("Very good!"); } else if (grade > 60) { System.out.println("Good!"); } else { System.out.println("Sorry you failed"); }
You want to print "Passed" if a student's grade is greater than 60, otherwise print "Failed."
Check if a number is positive, negative, or zero and print the corresponding message.
Determine whether a given year is a leap year or a common year.
Find the largest number among three given numbers.
You have multiple conditions to check, and if the first condition is true, you want to skip the rest.
You need to check if a number is even or odd and print the respective message.
What is the purpose of decision control structures in Java?
It provides for a multi-way branch. Thus, it enables a program to select among several alternatives.
What is the purpose of the break statement in a switch statement?
Multiple Correct Answers. Directions: Choose all the correct answers given.
Which data types can be used as the switch expression?
When using a switch statement, how are multiple statements executed?
In a switch statement, the default case is optional.
Execution continues into the next case if no break statement is present.
The switch expression can only be of type int.
A switch statement can be used for decisions based on ranges of values.
there can be two or more case constants in the same switch and can have identical values.
The switch statement allows branching on __________ outcomes.
Unlike with the if statement, multiple statements in the switch statement are executed without needing __________.
Unlike with the if statement, multiple statements in the switch statement are executed without needing __________.
Unlike with the if statement, multiple statements in the switch statement are executed without needing __________.
Which statements are true about nested if-else statements?
it is a switch statement within another switch statement
In the code snippet below, why is the equals method used instead of the == operator?
String pw = input.next();
String ans = input.next();
if (pw.equals(ans))
{
System.out.println("Hello World");
}
What is the difference between equals and == in Java?
Why might you choose to use a switch statement over an if statement in certain situations?