❮ Previous Next ❯

Java Ternary Operators(?:) ::

class ConditionalDemo
{
public static void main(String[] args)
{
int value1 = 1;
int value2 = 2;
int result;
result=(value1>value2) ? value1 : value2 ;
System.out.println(result);
}
}
Output

2

Here in above program the expression (value1>value2) is false, so In this example, result will be assigned the value of value2 that is 2. This can be achieved using the if…….else statement as follows :

if(value1>value2)
result=value1;
else
result=value2;
❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved