0
Can any one described how ternary operator work with examples?
2 ответов
+ 10
public static void main(String[] args) {
int a = 5;
boolean result1 = if_statement(a);
boolean result2 = ternary(a);
System.out.println("result1="+result1);
System.out.println("result2="+result2);
}
static boolean if_statement(int a){
if(a==5){
return true;
}else{
return false;
}
}
static boolean ternary(int a){
return a==5 ? true : false;
}
//Output
result1=true
result2=true