Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Defining a Advanced(-ish) Variable via Java?
I've seen Integers set queerly such in programs i've checked out.
I tried searching some reference over it, but I have failed to get the correct terms.
This is what It looks like:
int example = exampl : (exampl : (ausdn : ?));
Or so...
Could anyone link me a reference or explain in-depth on how it works?
I do my daily findings, and learn over it.
So let's say
int i = 1;
int example = (i == 1) ? i : i--;
Would execute correctly?
What I read was:
var = boolean ? equation : (or) equation;
How could I write this longer?
---
Awesome.
So to make a big combo using info...
int a = (boolean ? example : (boolean ? example 1 : example 2));
if true then a = example else if false then if true then if a = example 1 else false then a = example 2....
sweet!
2 Answers
- green meklarLv 77 years agoFavorite Answer
If you're talking about conditional expressions, the form is as follows:
(A?B:C)
where A is a boolean expression, B is the result value if A is true, and C is the result value if A is false (in general, B and C will be of the same type; the compiler may even insist on it). This syntax may be combined with other expressions however you like.
If you simply say:
D E=(A?B:C);
where D is a type and E is an identifier, this is considered equivalent to writing:
D E;
if(A)
{
E=B;
}
else
{
E=C;
}
However, as noted above, you may freely combine conditional expressions with other expression syntax.
- 7 years ago
I think you mean a ternary operator.
It's essentially a short hand way of writing an if-else statement.
Consider the following code:
http://pastie.org/private/ui8gz3rvj8ku1txqgmdsoq
(hosted on pastie so it retains formatting)
More on the ternary operator: http://en.wikipedia.org/wiki/%3F: