+ 1

What is the job of this question mark "?" in java?

13th Aug 2019, 3:55 PM
Shahid Iqbal
Shahid Iqbal - avatar
13 Respostas
+ 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 😉
13th Aug 2019, 4:22 PM
Mykola Romaniak
Mykola Romaniak - avatar
+ 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; }
13th Aug 2019, 5:17 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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
13th Aug 2019, 5:33 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
I created a program on same once https://code.sololearn.com/c0mjHQBT1ke3/?ref=app
13th Aug 2019, 4:25 PM
Sachin Artani
Sachin Artani - avatar
+ 2
Sachin Artani thank uh :)
13th Aug 2019, 5:26 PM
Shahid Iqbal
Shahid Iqbal - avatar
+ 1
I can ask java questions with ? At the end, like what do you mean?
13th Aug 2019, 4:03 PM
Sachin Artani
Sachin Artani - avatar
+ 1
give example, it can be ternary operator or wild card in generic type
13th Aug 2019, 4:16 PM
zemiak
+ 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.
13th Aug 2019, 4:16 PM
Sachin Artani
Sachin Artani - avatar
+ 1
Mykola Romaniak thank uh :)
13th Aug 2019, 5:25 PM
Shahid Iqbal
Shahid Iqbal - avatar
+ 1
13th Aug 2019, 5:26 PM
Shahid Iqbal
Shahid Iqbal - avatar
0
Mykola Romaniak bro help !!
13th Aug 2019, 3:56 PM
Shahid Iqbal
Shahid Iqbal - avatar
0
Sachin Artani can u plz give an example with code
13th Aug 2019, 4:15 PM
Shahid Iqbal
Shahid Iqbal - avatar
0
Yeah ?: I will take screenshot I saw it in question during that challenge
13th Aug 2019, 4:22 PM
Shahid Iqbal
Shahid Iqbal - avatar