Java-Preliminary Understanding-Chapter II-Arithmetic operators 2 continued

Source: Internet
Author: User
Tags arithmetic operators

I. Re-understanding of the self-increment operator

The first thing to understand is that operators are symbolic representations of operations, and each of these operators represents a specific operation. The forms of these operations are various, and here we will re-discuss the increment operator, which is the symbol + +.

A demonstration of the self-increment operator results in the following:

We began to assume that the increment is based on its own numerical value, the constant is added, the constant can not be 1, when we detect the error. There are two errors here, self-increment is fixed plus one, and the self-increment operator is fixed, that is, + + does not need to add a constant.

We re-wrote the Java source program, with the result of DOS detection:

Two. Talk about the case analysis of the self-increment operator when participating in complex operations

The DOS detection results show the error of missing precision. Shows that we are not familiar with the Java default type rules. b*a++, the computed result is the default int, when the result is assigned to a byte type, the current result is 12, although there is no more than the range of byte, but because the right side is the calculation of the variable, so the report is likely to be more than the range defined by the byte, so it shows " There may be a loss. " If we redefine an int c=1; c=b*a++; DOS results are displayed as normal. In the case of a constant int type, the system automatically determines the size and then enforces the type conversion. If it is an operator such as + =, the system will also automatically determine, cast.

If we are in the range of the main function, write the byte a=3,b=4 directly; and b*a++; Then the output b,dos will be displayed b*a++ is not a statement.

Java-Preliminary Understanding-Chapter II-Arithmetic operators 2 continued

Related Article

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.