ternary operator java

Solutions on MaxInterview for ternary operator java by the best coders in the world

showing results for - "ternary operator java"
Daniel
30 Jul 2019
1int val1 = 10;
2int val2 = 20;
3
4int max = val1 >= val2 ? val1 : val2;
5
Juanita
02 Jan 2017
1Object myObject = booleanExpression ? valueIfTrue : valueIfFalse;
Marceau
23 Jan 2021
1The condition part of a ternary operator is followed by a question mark (?). 
2After the question mark are the two values the ternary operator can return, separated by a colon (:).
3
4The values part consists of two values. The first value is returned if the condition parts evaluates to true.
5The second value is returned if the condition part evaluates to false.
Jenessa
19 Jun 2020
1// variable= condition ? value if condition is True : value if condition is false
2// only ternary operator in java
3int max,a=1,b=2;
4max= a>b ? a : b;
5
6//will result in max = b
Mía
10 Jun 2020
1booleanExpression ? expression1 : expression2;
2//expression1 if booleanExpression==true
3//expression2 if booleanExpression==false
Lorenzo
12 Oct 2019
1booleanExpression ? expression1 : expression2;