Java Program for If Else Conditional Statements

01. Example:

class ifElseConditionalStatements {
  public static void main(String[] args) {
    
    int number = 500;
    
    if (number > 100) {
      System.out.println("Condition is true. Input Is greater then 100.");
    } else {
      System.out.println("Condition is False. Input Is less then 100.");
    }
    
  }
}

Output:

Condition is true. Input Is greater then 100.


02. Example:

class ifElseConditionalStatements {
  public static void main(String[] args) {
    
    int number = 50;
    
    if (number > 100) {
      System.out.println("Condition is true. Input Is greater then 100.");
    } else {
      System.out.println("Condition is False. Input Is less then 100.");
    }
    
  }
}

Output:

Condition is False. Input Is less then 100.


03. Example:

import java.util.Scanner;

class ifElseConditionalStatements {
  public static void main(String[] args) {
    
    int marksObtained, passingMarks;
    passingMarks = 36;
    
    Scanner input = new Scanner(System.in);
    
    System.out.println("Enter Markes: ");
    marksObtained = input.nextInt();
    
    if (marksObtained >= passingMarks) {
      System.out.println("You passed The Exam.");
    } else {
      System.out.println("You failed.");
    }
    
  }
}

Output:

Enter Markes: 37
You passed The Exam.

Leave a comment