Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java For Automation

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java For Automation
  • What are Decision Making statements?

What are Decision Making statements?

What are Decision Making statements?

Decision-making statements allow a program to execute certain blocks of code based on specific conditions. 

1. if Statement: Executes a block of code if the condition is true.

Example : if Statement #

public class IfExample {

    public static void main(String[] args) {

        int age = 20;

        if (age >= 18) {

            System.out.println("You are eligible to vote.");

        }

    }

}

Output:
You are eligible to vote.

In this example, the condition age >= 18 is true, so the message is printed.

2. if-else Statement: Executes one block of code if the condition is true, and another block if the condition is false.

Example : if-else Statement #

public class IfElseExample {

    public static void main(String[] args) {

        int age = 16;

        if (age >= 18) {

            System.out.println("You are eligible to vote.");

        } else {

            System.out.println("You are not eligible to vote.");

        }

    }

}

Output:
You are not eligible to vote.

Here, since age >= 18 is false, the code in the else block is executed.

3. else-if Ladder: Checks multiple conditions sequentially and executes the corresponding block of code for the first condition that is true.

Example : else-if Ladder #

public class ElseIfExample {

    public static void main(String[] args) {

        int marks = 85;

        if (marks >= 90) {

            System.out.println("Grade A");

        } else if (marks >= 80) {

            System.out.println("Grade B");

        } else if (marks >= 70) {

            System.out.println("Grade C");

        } else {

            System.out.println("Grade D");

        }

    }

}

Output:
Grade B

The program checks conditions sequentially until it finds a true condition. Since marks >= 80 is true, “Grade B” is printed.

4. Nested if statements in Java are if statements placed inside another if statement. This structure is used to check multiple conditions, where each condition is dependent on the previous one.

Example : Nested-if  #

This program determines the largest of three numbers using nested if statements.

public class LargestNumberExample {

    public static void main(String[] args) {

        int num1 = 10;

        int num2 = 20;

        int num3 = 15;

        if (num1 >= num2) {

            if (num1 >= num3) {

                System.out.println("The largest number is: " + num1);

            } else {

                System.out.println("The largest number is: " + num3);

            }

        } else {

            if (num2 >= num3) {

                System.out.println("The largest number is: " + num2);

            } else {

                System.out.println("The largest number is: " + num3);

            }

        }

    }

}

Output:
The largest number is: 20

This program demonstrates how nested if statements can be used to evaluate multiple dependent conditions and make decisions based on those conditions.

5. switch Statement: Evaluates a variable and executes a block of code based on the matching case.

Example : switch Statement #

public class SwitchExample {

    public static void main(String[] args) {

        int day = 3;

        String dayName;

        switch (day) {

            case 1:

                dayName = "Sunday";

                break;

            case 2:

                dayName = "Monday";

                break;

            case 3:

                dayName = "Tuesday";

                break;

            case 4:

                dayName = "Wednesday";

                break;

            case 5:

                dayName = "Thursday";

                break;

            case 6:

                dayName = "Friday";

                break;

            case 7:

                dayName = "Saturday";

                break;

            default:

                dayName = "Invalid day";

                break;

        }

        System.out.println("Day: " + dayName);

    }

}

Output:
Day: Tuesday

The switch statement evaluates the day variable and executes the matching case.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
What is Java Control Statements?What are looping statements?
Table of Contents
  • Example : if Statement
  • Example : if-else Statement
  • Example : else-if Ladder
  • Example : Nested-if 
  • Example : switch Statement
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105