Absrtact: Here everyone is familiar with the two symbols, all know that the trinocular operator is a shortcut mechanism for If/else control statements (Boolean expressions)? Statement: Statements such as if/else, like the execution, but three mesh operation also has a hidden data type conversion function, + = and-= is also not only add or subtract after the assignment, let us use a few examples to illustrate their hidden function.
I. Three-mesh operator:
Trinocular operator: When there is inconsistent data type, it will show the type of conversion, that is, it is loaded under the function of no conversion, not fit on the conversion;
Cases:
Package Com.lov.lianxitext;public class Valhold {public static void main (string[] args) {int a = 1; System.out.println (true?) ' B ': 65535);//' B ' is a character type, and 65535 is int type System.out.println (true?) ' B ': 65536); System.out.println (false? A: ' B ');}}
If we do not know its hidden function, only with three mesh operation, everyone will think the output is 98 98 98! But will that be the case?
Because ' B ' is a character type 65535 is an int, the character size is 2 bytes equal to the size of short, that is, the maximum positive integer that can be loaded is 65535, when more than, ' B ' will convert the data type to int output B ASCLL code 98
Two. + = and-=:
The addition and subtraction assignment symbol also has the conversion function of the data type;
Cases:
Package Com.lovo.javaoo2;public class TXET {public static void main (string[] args) {char[]array={' H ', ' e ', ' l ', ' l ', ' o ', '! '} ; changecase (array);} public static void ChangeCase (Char[]array) {for (int i = 0; i < Array.Length; i++) {if (array[i]>= ' A ' &&array[i ]<= ' Z ') {array[i]+=32;//①}else if (array[i]>= ' a ' &&array[i]<= ' Z ') {array[i]= (char) (array[i]-32);// ②}}}}
As the above code ① and ② comparison, we can see that the addition of the assignment has a type of conversion function.
The three-mesh operator and the mysterious function of + = and-=