Java and Java
1. Problem background
The result of the following code is:
A. hai
B, 1987
C, 1988
D. None of the above answers
/*** The Three-object operator * A, hai * B, 1987 * C, 1988 * D, and the above answers are incorrect */package com. you. model;/*** @ author YOUHAIDONG **/public class YesNo {/*** @ param args */public static void main (String [] args) {// declare an integer variable youint you = 56; // string strString str = (you <50 )? "Hai" :( you> 60 )? "1987": "1988"; // print strSystem. out. println (str );}}
2. Problem Analysis
(1) Since the variable you is 56, 56 is greater than 50, and false, yes: (you> 60 )? 1987: 1988"
(2) If 56 is less than 60, the value is false. Select 1988.
3. Answer
1988
Java three-object Operator
First, for? B: c Operator. When a is true, the calculation result is B. When a is false, the calculation result is c;
Then, the explanation of the above question:
The operation must be performed on the same data type. So, true? In x: 1111111110, because x is char type, 1111111110 is int type, and int type is greater than char type, x is automatically converted into int type data During computation, 'B' is converted to an int value equal to 98. Therefore, 98 is output;
Similarly, false? In I: x, I is int type and x is char type. Therefore, all data is converted to int type, that is, x is converted to 98, because? The value on the left is false, so the output value of x is 98.
If you still don't understand it, you can ask me ^_^.
For java three-object Operators
Everything works .? The first is the judgment condition, followed by the output values on both sides.
Public class Three {
Public static void main (String [] args ){
System. out. println (1 = 1? 'Y': 'n ');
}
}
In this simple example, the output is y.