Java-Conditional-Operator .

In this session i have discussed conditional operator in Java .


Conditional-Operator :

Conditional Operator also known as ternary operator(?:) . It is look like below .

        expression1 ? expression2 :expression3    
    

It uses the three operands . The first operand is used to give the condition and if the condition is true then second operand will be evaluate other wise third operand will be evaluate .

Example : Write a java program that will check the maximum value among two values .

 class Hello{ 
         
      public static void main(String args[]){  
            int x=35;
            int y=20;
            int max=(x>y)?x:y ;
            System.out.println("MAX= "+max);
      }
 } 
    OUTPUT : MAX=35
    


Welcome to AndroidATPoint.

back image                     next image