Java arithmetic operations

Source: Internet
Author: User

Java arithmetic operations
Arithmetic Operators:

Addition (+) subtraction (-) multiplication (*) Division (/) modulo (%)

Addition:

String type: String concatenation.

Division:

1.0/0 show Infinity

0.0/0.0 shows NaN: not a number is not a value

0.0/0.0 = 0.0/0.0 if java itself is not equal to itself, the result is false.

The modulo operation is also called the remainder operation.

Auto-increment and auto-increment:

Auto-increment and auto-increment can only be used for variables: The operator has a higher priority than other operators.

Calculation rules:

1. the auto-increment operation acts on the variable itself (I ++ I)

Variable value increases by 1

2. assign a value to another variable using the result of a variable and an auto-increment operator expression.

1. the auto-increment operator is on the right side: the result of the expression is the original value of the variable and serves as the result of the expression. The variable is still auto-incrementing.

2. the auto-increment operator is on the left: The result of the expression is the self-incrementing value of the original value of the variable, which is used as the result of the expression. The variable will still be auto-incrementing

3. Use the result of a variable and an auto-increment operator expression to assign a value to the variable itself.

Y = y ++: First cache the expression results, then auto-increment, and finally assign the expression results to y

Y = ++ y: The result of the expression is the auto-increment of the original value of the variable, and the result of the expression is assigned to y.

Assignment operator:

The operator number is: = + =-= * =/= % =

Assign values from right to left

Implicit conversion exists, for example, I * = 2.0I = I * 2.0The actual result is the defined Int.Type

Comparison Operators

Symbol: =! ==<>=<=Instanceof (Type comparison operator, which can only be used for reference type data comparison)

Note:

Calculation rules of Instanceof:

The value variable or expression must be of the instanceof type.

Logical operators

& (And) | (OR)&&(Double and logic and)|(Double or logical or)^Exclusive or! Non

Rules for logical operators:

&: Both sides are true, and the result is true.

|: If one side is true, the result is true.

&: Both sides are true, and the result is true.

|: If one side is true, the result is true.

^: The two sides are different. The result is true. Otherwise, the result is false.

! : Non-logical

1. The parameters on both sides and the Data Type of the operation are boolean.

2. The result type of the logical operator expression is boolean.

Functions of logical operators:

Is a combination of multiple conditions.

& | And & | Differences:

& | It can act as either a logical operation or a bitwise Operator

Determine whether the expression is boolean.

& | Short circuit:

&: When the current side is false, the expression after the result of the entire expression is false is no longer computed.

|: When the current plane is true, the expression after true is not included in the operation.

Bit operations (understanding)

Concept: binary operations regard 1 as true, and 0 as false.

Arithmetic Operation: Syntax:

A? B: C

A: A boolean expression.

The result types of B and C are generally the same.

Rules

Result Based on A: If true, the result of the entire three-object operator expression is the result of expression B.

If it is false, the result of the entire three-object operator expression is the result of the c expression.

Note:

The three-object operator requires a variable to receive

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.