I am having trouble understanding the following expression return and subsequent notation.
private String fm(float value){
return(value<=0)??"+value:"+"+value;
}
Is it a kind of if sentence?I think so, but I can't search the book with this code because there's no explanation.
?
I don't know much about it, so I would appreciate it if you could explain it to me.
It is called a trinomial operator.
(value<=0)??"+value:"+"+value
in one lump,
If (value<=0)
is a conditional statement, and if it is true, it returns ?
and :
(where "+value
), and if it is false, :
or later (where +value
).
The Java specification is "conditional operator" in 15.25.Conditional Operator?:.In Japanese, is it conditional operator?The term triplet operator may be better.
Equivalent to the following if
statement:
private String fm(float value){
if(value<=0){
return""+value;
} else{
return"+"+value;
}
}
© 2024 OneMinuteCode. All rights reserved.