Ternary operator Demo : Ternary operator « Language Basics « Java






Ternary operator Demo

 

public class ConditionalOp
{
   public static void main(String args[]) 
   {
      int value = 1;     
      System.out.println("I have " + value + " hat" + (value == 1 ? "." : "s."));

      value++;           
      System.out.println("I have " + value + " hat" + (value == 1 ? "." : "s."));
   }
}

 








Related examples in the same category