Dark Horse programmer-java basics-Basic Knowledge (2), dark horse java

Source: Internet
Author: User

Dark Horse programmer-java basics-Basic Knowledge (2), dark horse java

 

------ Android training, java training, and hope to communicate with you! ------

I. Operators in java

In java, operators can be classified into-Arithmetic Operators, value assignment operators, comparison operators, and bitwise operators.

1. Arithmetic Operators

Arithmetic Operators are used in mathematical expressions. They play the same role as in mathematics.

Operator Description Example
+ Values on both sides of the addition-addition Operator A + B
- Subtraction-left operand minus right operand A-B
* Multiplication-values on both sides of the multiplication Operator A * B
/ Division-left operand divided by right operand B/
% Modulo-remainder of the left operand B %
++ Auto-increment-the operand value is increased by 1 B ++ or ++ B
-- Auto-Subtract-the operand value is reduced by 1 B-or -- B

 

For example:

Public class Test {

Public static void main (String [] args ){
Int a = 60;
Int B = 30;
Int c = 20;
Int d = 20;
Int e = 20;
Int f = 20;
System. out. println ("a + B =" + (a + B ));
System. out. println ("a-B =" + (a-B ));
System. out. println ("a * B =" + (a * B ));
System. out. println ("a/B =" + (a/B ));
System. out. println ("a % B =" + (a % B ));

// ++ I (f = "+ () indicates that after using the I variable, the I value is added (subtracted) 1;
System. out. println ("Before calculation c =" + c + ";" + "in calculation c ++ =" + (c ++) + "; "+" c = "+ c );
System. out. println ("e =" + e + ";" + "e) +"; "+" e = "+ e );

}
}

After compilation, It is shown as follows:

 

2. Value assignment operator
Operator Description Example
= A simple value assignment operator assigns the value of the right operand to the left operand. C = A + B will assign the value obtained by A + B to C
+ = The addition and value assignment operator that adds the Left and Right operations to the left operations. C + = A is equivalent to C = C +
-= Subtraction and value assignment operator, which subtract the Left and Right operands and assign them to the left operands C-= A is equivalent to C = C-
A
* = Multiplication and value assignment operator, which multiply the Left and Right operands and assign a value to the left operand C * = A is equivalent to C = C *
/= Division and value assignment operator, which separates the Left and Right operations and assigns the value to the left operations. C/= A is equivalent to C = C/
(%) = Modulo and value assignment operator. It modulo the Left and Right operands and assigns them to the left operands. C % = A is equivalent to C = C %
<= Left shift assignment operator C <= 2 is equivalent to C = C <2
>>= Right shift assignment operator C> = 2 is equivalent to C = C> 2
& = Bitwise AND value assignment operators C & = 2 is equivalent to C = C & 2
^ = Bitwise exclusive OR value assignment operator C ^ = 2 is equivalent to C = C ^ 2
| = Bitwise OR value assignment operator C | = 2 is equivalent to C = C | 2

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.