Recall & Review
beginner
What is the purpose of an
if statement in Java?An
if statement lets the program decide to run some code only if a condition is true. It helps the program make choices.Click to reveal answer
beginner
Write the basic syntax of an
if statement in Java.The basic syntax is:<br>
if (condition) {<br> // code to run if condition is true<br>}Click to reveal answer
beginner
What happens if the condition in an
if statement is false?If the condition is false, the code inside the
if block does not run. The program skips it and continues.Click to reveal answer
beginner
Can an
if statement be used without an else part?Yes, an
if statement can stand alone. The else part is optional and runs code when the condition is false.Click to reveal answer
beginner
How do you write an
if-else statement in Java?You write it like this:<br>
if (condition) {<br> // code if true<br>} else {<br> // code if false<br>}Click to reveal answer
What does the
if statement check in Java?✗ Incorrect
The
if statement checks a condition that evaluates to true or false to decide which code to run.What happens if the
if condition is false and there is no else?✗ Incorrect
If the condition is false and no
else is present, the program skips the if block and continues.Which of these is the correct syntax for an
if statement?✗ Incorrect
In Java, the condition must be inside parentheses:
if (condition) { }.Can you have multiple
if statements one after another?✗ Incorrect
You can have many
if statements in a program to check different conditions.What keyword do you use to run code when an
if condition is false?✗ Incorrect
The keyword
else runs code when the if condition is false.Explain how an
if statement works in Java and write a simple example.Think about how you decide to do something only if a certain condition is true.
You got /4 concepts.
Describe the difference between an
if statement and an if-else statement.Consider what happens when the condition is false.
You got /4 concepts.