Categories
java

If else condition in java

If else condition in java

In this tutorial, we will learn about If else condition in java

if else is used to check the logical condition in java

Syntax of If condition

if(condition){
// your logic can be written here
}

Syntax for if else

if(condition){
// your logic can be written here
}
else{
// else logic
}

Syntax for else if 

if(condition){
     // your if logic can be written here
}
else if {
     // your else if logic can be written here
}
else{
     // else logic
}

Example

public class IfConditonExample {
	  
	public static void main(String[] args) {
       int i = 1;
       if (i > 1) {
           System.out.println("I is greater than 1");
       } else if (i < 1) {
          System.out.println("I value less than 1");
       } else {
          System.out.println("I value is 1");
       }
    }
}

Output

I value is 1
Reference

https://github.com/rkumar9090/BeginnersBug/blob/master/BegineersBug/src/com/geeks/example/IfConditonExample.java

Leave a Reply

Your email address will not be published. Required fields are marked *