Ternary Operator in Detail




This video tutorial made by the Learning Lad explains the ternary operators available in java programming.

You will learn what are ternary operators along with its syntax, how to use them instead of if and else, how they work in detail with example.


Source code for this video tutorial


package learningJava;

public class Anil {
 public static void main(String[] args) {

  int num1 = 100, num2 = 200;
  int max;
  
  max = num1 > num2 ? num1 : num2;
  
  
 /*
  if( num1 > num2){
   max = num1;
  }else{
   max = num2;
  }
  */
  
  System.out.println(max);

 }

}

Back To Top