If Condition Java


if condition is a control operator that checks a particular condition input and can perform one of two case ie

  • 1.   input condition is true
  • 2.   input condition is false


Nested if condition is an if condition inside another if condition control statement


eg



1. myClass.java:

package control_statements_1;

public class myClass {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		// condition control variable
		boolean check=true;
		
		if(check) {
			System.out.println("Condition is true");
		}else {
			System.out.println("Condition is false");
		}
		
		
		// Nested if condition
		
		System.out.println("nested if condition");
		boolean check2=true,check_nested=false;
		if(check2) {
			System.out.println("Condition_2 is true");
			if(check_nested) {
				System.out.println("Nested Condition is true");
			}else {
				System.out.println("Nested Condition is true");
			}
		}else {
			System.out.println("Condition_2 is false");
		}

	}

}
output:
Condition is true
nested if condition
Condition_2 is true
Nested Condition is true




Related Tutorials