Slide 1
Slide 2
Slide 3

If else if else statement in java programming (V36)

No Comments

If Else If Statements

if else if is used to apply multiple conditions after an if statement. It means that if the condition in the if statement is False, it will continue checking the next condition inside the else if. If that condition is True, it will execute the block of code that is defined.

Syntax:

Source Code:

Copied!
import java.util.Scanner;

public class LoanEligibility {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Input details from user
        System.out.print("Enter your age: ");
        int age = scanner.nextInt();

        System.out.print("Enter your monthly salary: ");
        double salary = scanner.nextDouble();

        System.out.print("Enter number of months in current job: ");
        int monthsEmployed = scanner.nextInt();

        // Checking conditions using if-else if-else
        if (age < 21 || age > 60) {
            System.out.println("Sorry, you are not eligible for a loan due to age restrictions.");
        } else if (salary < 300) {
            System.out.println("Sorry, your salary is too low for loan eligibility.");
        } else if (monthsEmployed < 6) {
            System.out.println("Sorry, you need at least 6 months of employment to be eligible.");
        } else {
            System.out.println("Congratulations! You are eligible for a loan.");
        }

        scanner.close();
    }
}

Result:

Watch the video:


Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

back to top