Ternary Operators Def: In ternary operators we use 3 operands. syntax: expr1 ? expr2 : expr3 Note: Result of expr1 should be boolean in java. Demo: public class Ternary{ public static void main(String args[]){ //ternary operator int a=5; System.out.println( a>4 ? "a is greater than 4" : "a is less than equal to 4"); } } output is: a is greater than 4

No comments:
Post a Comment