is the + number an operator or a connector?

Source: Internet
Author: User

Implement the following procedure to observe the results

int x=100;

int y=200;

System.out.println ("x+y=" +x+y);

System.out.println (x+y+ "=x+y");

It turned out to be

Reason:

In Java, + is sometimes an operator, sometimes a connector

1) when both left and right connections are non-numeric, the connector.

2) is a connector when one side is a numeric type and the other is a non-numeric type.

3) When both sides are numeric types, the operator, that is, the function of the summation sum

System.out.println (str) itself outputs a string, and according to the precedence rules of the operator,

System.out.println ("x+y=" +x+y), the statement is the output string X (100) after the output string Y (200), so the output of the statement is x+y=100200;

and System.out.println (x+y+ "=x+y"), the statement is to first convert the string X and Y to Ascall code, and then add the output after the addition of the result of 300, so the output is 300=x+y.

is the + number an operator or a connector?

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.