If-else Statement in Java

If-else Statement in Java is used to test conditions.The return type for an if statement is either true or false.There are different types of if statements in Java:-

  • if statement
  • if-else statement
  • nested if statement
  • if-else-if ladder statement

1.if statement

if statements check a condition and code block is executed when a true boolean is returned.

Syntax:

Output:

If-else Statement in Java

 

 

 

 

2.If-else Statement in Java

if-else statement has two code blocks.If the condition is true, one block is executed, and if the condition is false, the alternative code block is executed.

Syntax:

Example:


 3.if-else-if ladder statement

if-else-if ladder statement executes just one condition from a choice of several statements.

Syntax:

Example:

About the Author: Eric K

Kenyan Developer and Blogger with Interests in Java,Javascript,Node.js, Wordpress, Android, PHP and Making Money Online. Solving world problems through programming is my passion. Hire me: Email : kawi3462@gmail.com