+ 1
What is the job of this question mark "?" in java?
13 Answers
+ 2
It's called 'ternary operator'.
The general form of writing the ternary operator is next:
condition ? true : false
For example:
System.out.println(5 > 2 ? "A" : "B");
will output "A"
and
System.out.println(5 > 7 ? "A" : "B");
will output "B"
There can be write more complicated kind of the ternary operator, but it doesn't change its matter.
I hope you easy understand example above.
Good luck 😉
+ 7
The conditional operator, ?: , is a shorthand for an if-then-else construction that does one of two different things depending upon the result of a boolean expression.
The expression:
variable = booleanExpr ? value1 : value2;
has the same effect as:
if( booleanExpr ) {
variable = value1;
} else {
variable = value2;
}
+ 6
Shahid Iqbal You are welcome!😊
Please,
Remember to use 🔍SEARCH... bar future you can find many similar threads!
• https://www.sololearn.com/post/10362/?ref=app
+ 2
I created a program on same once
https://code.sololearn.com/c0mjHQBT1ke3/?ref=app
+ 2
Sachin Artani thank uh :)
+ 1
I can ask java questions with ? At the end, like what do you mean?
+ 1
give example, it can be ternary operator or wild card in generic type
+ 1
Shahid Iqbal Can you give the example with code, so that we can understand where you saw that question mark alone?
There is a ternary operator i.e. ?: which you might be asking.
+ 1
Mykola Romaniak thank uh :)
+ 1
Danijel Ivanović thank uh :)
0
Mykola Romaniak bro help !!
0
Sachin Artani can u plz give an example with code
0
Yeah ?: I will take screenshot I saw it in question during that challenge