Sunday 10 June 2018

Ternary Opereator In Java || If Then Else Operator In Java || Java Techn...

Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.








Ternary Operator in Java

-------------------------------------



- This operator is named so because it is the only operator

to take three operands.



- It is a conditional operator that provides a shorter syntax

   for the if...then...else statement.

 

- The first operand is a Boolean expression, if the expression

   is true then the value of the second operand is returned,

   otherwise the value of the third operand is returned.



----------------------------



Syntax



evaluation part ? codes_of_true : codes_of_false;



--------------------------------------------------------------------



public class Ternary

{

public static void main(String args[])

{

int i = 64;

double k =40.0;

int b = (i>k)?10:5;

System.out.println("b : "+b); //10

b = (i<k)?10:5;

System.out.println("b :"+b); //5

}

}



------------------------------------------------------



public class Ternary1

{

public static void main(String args[])

{

int a=5;

//int b = (int)((a==6)?5:10.0);

System.out.println((a==6)?5:10.5);

}

}



-----------------------------------------------------------

No comments:

Post a Comment