if then else and nested if and else




This video tutorial made by the learninglad explains the if then else and nested if and else in java programming.

You will learn how to execute statements depending on the several conditions, how to nest if and else in java in detail with example.

Source code for this video tutorial


package learningJava;

public class Chocolate {
 public static void main(String[] args) {  
  int chocolate = 1;
  boolean money = false;
  
  if( chocolate == 1 ){
   System.out.println("One chocolate");
   System.out.println("am gonna eat it");
   
   if(money){
    
    System.out.println("am gonna buy more chocolates");
   }else{
    System.out.println("No money bad luck");
   }
   
  }else if( chocolate == 2 ){
   System.out.println("Two chocolate");
   System.out.println("am gonna eat one and give one to my GF");
   
  }else if( chocolate == 3 ){
   System.out.println("Three chocolate");
   System.out.println("am gonna eat one and give one to my GF and my BEst Friend");
  }else{
   System.out.println("more than Three chocolate");
   System.out.println("am gonna share it wil all my friends");
   
  }
  
 }

}


Back To Top