The three-mesh condition operation formula is x?y:z where X's operation result is Boolean type, first calculates X's value, if true, then the entire three-mesh operation result is the expression Y's value, otherwise the entire operation result is the expression Z's value
Example: String s= "";
String x= "Default value";
S=s.isempty () x:s;
This code means: first to determine whether S is empty (the result is empty), and then execute s=x, that is, execute X
A little more complicated.
Class Dates {
int year,month,day;
Dates (int x,int y,int z) {
year=x;
month=y;
day=z;
}
public static int compare (dates a) {return
year>a.year?1
: year<a.year?-1
: month>a.month?1
: month<a.month?-1
:d ay>a.day?1
:d ay<a.day?-1:0;
}
1, three-mesh operator (expression 1)? (expression 2):(expression 3), the calculation method is as follows: Expression 1 is a logical expression, and if its value is true, the value of the entire expression is the value of expression 2, otherwise the value of the expression 3
2. Example: int i = (5 > 3)? (5 + 3): (5-3); The result is i = 8. Because 5 > 3 is true, I = 5 + 3.
3, according to the three-mesh operator from the right to the left of the binding, I was so divided
Year > A.year? 1: (Year < A.year)-1: (Month > A.month 1: (Month < a.month?-1: (Day > A.day? 1: (Day < A.day? -1:0)));
So you should start with the expression on the far right, and the result should be a value in 1, 0,-1.
The above is purely personal understanding. I don't know what you mean by this algorithm ....
Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!