Explain the usage of IF Statement in Java.
Advertisements
Question
Explain the usage of IF Statement in Java.
Explain
Advertisements
Solution
The if statement in Java is a decision-making or conditional statement used to execute a block of code only when a specified condition is true. It allows the program to make decisions and control the flow of execution based on a condition.
Working of the if Statement
- The
ifstatement evaluates a condition that produces eithertrueorfalse. - If the condition is true, the statements inside the
ifblock are executed. - If the condition is false, the statements inside the
ifblock are skipped. - After executing or skipping the
ifblock, program control moves to the next statement.
Syntax:
if (condition) { }
shaalaa.com
Is there an error in this question or solution?
