Java – if-else statement1 min read

There are two-part in an if-else statement. First is the if statement, here it checks for the condition to be true and if it is true then it will execute the code present inside the if-block. But if the condition is false then the code inside the else statement will be executed.

if-else statement

Syntax of an if-else statement:

Example of an if-else statement in Java:


if statement.
nested if statement.
if-else-if ladder.
switch statement.