Java and Java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.