I. Three-mesh operator
Ternary operators generally use very little, because it is very poor readability in the program section, so I recommend not to use the ternary operator often, but very little use does not mean not to use, so still have to master its usage, ternary operator expression is as follows:
boolean expression? Value 0: value 1
Its operation is to return a value of 0 if the result of the Boolean expression is true, and return a value of 1 if the result of the Boolean expression is false, for example, the following program segment.
public class data21{
public static void Main (string[] args) {
int a=10;
int b=20;
SYSTEM.OUT.PRINTLN ("The result of this ternary expression is:" + ((a>b)? ') A ': ' B '));
}
}
Analysis of the above program segment: Because "a" is less than "B", so "a>b" the result of the relational operator is "false", since it is "false", then choose the value 1, that is, the result of this ternary operator is "B".
Two. Comma operator
In Java programming, the comma operator is generally used to separate several conditions from each other, for example, each element in an array is separated by a comma from other elements.
public class var{
public static void Main (string[] args) {
int a=1,b=2,c=3;
System.out.println (A+B+C);
}
}
Output Result:
6
8.Java three mesh operator and comma operator