How to Use a Method with Ifelse in Java


In this example we will show you how to use a method with if…else in Java.

Source Code

package com.beginner.examples;

public class IfElse {
  static void test(int i ) {
    // use if...else
    if(i > 3) {
        System.out.println("It is greater than 3."); 
    } else {
        System.out.println("It is not greater than 3."); 
    }
  }

  public static void main(String[] args) { 
    int a = 5;
    test(a);
  }
}

Output:

It is greater than 3.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments