The small problem of 2:java compound assignment expression in Java learning essay

Source: Internet
Author: User

Question: i + = j is just the shorthand for i = i + j?

Answer: not also! Look at the following program:

int i = 5; long j = 8+ = j;    // can be compiled and the result is correct i = i + j;    // cannot compile, type conversion issues

In fact, Java will convert i + = j to i = (int) (i + j) to execute.

Typically, a compound assignment expression in the form of a E1 op= E2 is equivalent to E1 = (t) ((E1) + (E2)) and T is the type of E1.

Ps:java how to generate an integer of interval (such as 100-200)?

For:

 Public Static int randint (intint  min) {                Random rand;         int randnum = Rand.nextint ((max-min) + 1) + min;         return randnum;      }

The small problem of 2:java compound assignment expression in Java learning essay

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.