Dark Horse Programmer--java Foundation--Basic knowledge (II.)

Source: Internet
Author: User
Tags bitwise

—————— Android Training, Java training, look forward to communicating with you! ——————

An operator in Java

In Java, operators can be divided into-arithmetic operators, assignment operators, comparison operators, and bit operators.

1. Arithmetic operators

Arithmetic operators are used in mathematical expressions, and they function in the same way as they do in mathematics.

operator Description Example
+ Values on both sides of the addition-add operator A + B
- Subtraction-left operand minus right operand A–b
* Multiply-multiplies the values on both sides of the operator A * B
/ Division-left operand divided by right operand b/a
Modulo-right operand in addition to the remainder of the left operand B%a
+ + Self-increment-operand value increased by 1 B + + or ++b
-  - Auto minus-operand value reduced by 1 B--or--b

Specific uses such as :

public class Test {public static void main (string[] args) {int a = 60;         int B = 30;         int numbera = 20;         int numberb = 20;         int NUMBERC = 20;    int numberd = 20;    System.out.println ("a+b =" + (a+b));    System.out.println ("A-B =" + (a));    System.out.println ("a*b =" + (a*b));    System.out.println ("A/b =" + (A/b));        System.out.println ("a%b =" + (a%b)); ++i (-i) indicates that the value of I is added (minus) 1 before using the I variable, System.out.println ("Numberb =" +numberb+ "before operation); + "Operation + + + Numberb =" + (++numberb) + ";"    + "after operation Numberb =" +numberb); System.out.println ("Numberd =" before operation = "+numberd+"; + "operation--numberd =" + (--numberd) + ";"   + "after operation Numberd =" +numberd); i++ (I-) means that after using the I variable, the value of I is added (minus) 1; System.out.println ("Numbera =" +numbera+ "before operation," + "in Numbera + + =" + (numbera++) + ";    After the "+" Operation Numbera = "+numbera"); System.out.println ("Numberc =" before operation = "+numberc+"; "+" Operation in Numberc--= "+ (numberc--) +"; "    + "after operation Numberc =" +NUMBERC);   }     }  
 after compiling, it appears as follows:

2. Assignment operators

The function is to assign the value of a constant, variable, or expression to a variable.

operator Description Example
= A simple assignment operator that assigns the value of the right operand to the left operand c = A + B assigns the value obtained by A + B to c
+ = Add and assign operators, which add the left and right operands to the left operand c + = A is equivalent to C = C + A
- = Minus and assignment operators, which subtract left and right operands to the left operand C-= A is equivalent to C = C-
A
* = Multiply and assign operators, which multiply the left and right operands by assigning the left operand the value of c * = A is equivalent to C = c * A
/ = In addition to the assignment operator, it assigns the left operand and the right operand to the left operand by dividing the number of c/= A is equivalent to C = c/a
(%) = Modulo and assignment operators, which take the left operand and the right operand to the left operand after modulo c%= A is equivalent to C = c%a
<< = Left Shift assignment operator c << = 2 equivalent to C = C << 2
>> = Right Shift assignment operator c >> = 2 equivalent to C = C >> 2
&= Bitwise-and-assignment operators C&= 2 is equivalent to C = c&2
^ = Bitwise XOR or assignment operator c ^ = 2 equivalent to C = c ^ 2
| = Bitwise OR Assignment operators C | = 2 equivalent to C = C | 2

Dark Horse Programmer--java Foundation--Basic knowledge (II.)

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.