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

My name is Eric.Am a software developer with skills in Php,Mysql, Java , Android,Node.js Above all, I have certification in Cisco Networking Associate (CCNA) and holds degree in Information Technology. Hire me: Email : kawi3462@gmail.com