Java Learning: Operations, operators, operands, expressions

Source: Internet
Author: User
Tags arithmetic operators joins

Operation: The process of manipulating constants and variables is called arithmetic.

Number of operations: The constant or variable that participates in the operation is called the operand.

Operator: symbols that operate on constants and variables are called operators.

Arithmetic operators: + 、-、 *,/,%, + + 、--

 

/and% of the difference?
    /: Division, get quotient
The same symbol is positive and the difference is negative
%: Division, get remainder
The symbol is the same as the first operand

% of applications:
x%3 equals 0 means x can be divisible by 3.
x%2 etc 1 description x is odd
Wait 0 to indicate that X is an even number

   

  + +,--operator
   Function: + + is added 1,--is minus 1.
Self-increment auto-decrement operator

+ +,--can be placed in front of the operand, or after the operand, at the time of operation
A: Use alone
No difference.
B: Participate in other operations using
Back: First operation, then self-increment
Front: Self-increment first, then operate


Assignment operators

   Basic: =
Extension: + =

The extended assignment operator implies a forced type conversion:
int a = 10;
A + = 20;
A = (data type of a) (A + 20)


comparison Operators :

  ==,!=,>,>=,<,<=

Attention:
A: The result of the comparison operator is definitely a Boolean.
B: Whether you are using "=" or "= =", you need to know for yourself.


logical operators : &, |,! , ^, &&, | |

Attention:
logical operators for connecting relationship expressions

Conclusion:
&: False if False
|: True is true
!: Change the result, take the inverse
^: same false, different true
Memory: Couple relationship (male, female, male, female)

The most commonly used logical operators;
!,&&,| |

&& and &:
The result is the same, but the && has a short-circuit effect, the left side is false and the right side is not executed.
|| and |:
As a result, but | | With short-circuit effect, left if true, the right side is not executed.


Trinocular operator

Format:?:

(comparison expression)? Expression 1: Expression 2;

Execution process:
If the condition is true, the result of the operation is an expression of 1;
If the condition is false, the result of the operation is an expression of 2;
Requirements: Get the maximum value from two data
Nested use (Gets the maximum of three numbers)

An expression: a formula that joins a constant or variable with an operator that conforms to the Java syntax can be called an expression.
The expressions of different operator joins represent different types of expression.

Java Learning: Operations, operators, operands, expressions

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.