Decision and control statements

In Java, decision and control statements allow you to select and execute specific blocks of the code while skipping other sections or statements.

The if statement

The if statement consists of a condition followed by one or more statements.

The syntax of an if statement is as follows:

if(condition) 
{ 
    //Statements will execute if the condition is true 
}

An example of this is as follows:

package MyFirstPackage;
  public class IfCondition {
  public static void main(String[] args) {
    int empSal = 20000;
    if (empSal >= 10000) {
      System.out.println("he is a manager...!");
    }
    else 
    {
      System.out.println("he is NOT a manager...!");
    }
  }
}

The output of the preceding code is as follows:

he is a manager...!

The if...else statement

The if statement ...

Get Learning Selenium Testing Tools - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.