The correct answer is: A. if … then ..else
An if-else statement is a selection control structure that allows you to execute one block of code if a condition is true, and another block of code if the condition is false.
The syntax for an if-else statement is as follows:
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
The condition is a Boolean expression that evaluates to either true or false. If the condition is true, the code inside the if block is executed. If the condition is false, the code inside the else block is executed.
For example, the following if-else statement prints “Hello” if the variable x
is greater than 0, and “Goodbye” if it is not:
if (x > 0) {
System.out.println("Hello");
} else {
System.out.println("Goodbye");