Thursday, 26 April 2018

Core Java: Conditional Operator

Conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions.
 
variable x =(expression)? value iftrue: value iffalse
 
public class Test{
public static void main(String args[]){
int a , b;
a =10;
b =(a ==1)?20:30;
System.out.println("Value of b is : "+  b );
b =(a ==10)?20:30;
System.out.println("Value of b is : "+ b );
}
}
 
This would produce the following result:
 
Value of b is:30
Value of b is:20

No comments:

Post a Comment

Please write your view and suggestion....