1. Assignment operator
= assigned value
eg
int cadence = 0;int Speed = 0;int gear = 1;
2. Basic mathematical operators
+ Plus (both sides are numeric variables or values for mathematical operations, one of which is a character variable or value as a JOIN operation)
-Minus
* Multiply
/except (two integers for division, ending rounding, Original:integer division rounds toward 0)
% take-up
3, unary operators
+ Indicates positive number
-Indicates negative numbers
+ + increment operation adds 1 each time. Before the variable is represented by +1, then the variable is used, after which the variable is used, and then +1
--the self-subtraction operation is reduced by 1 each time. Before the variable is represented by-1, and then the variable is used after the variable is used, and then 1
! Logical operators, taking the inverse
int i = 3;i++;//prints 4system.out.println (i); ++i; Prints 5system.out.println (i);//Prints 6system.out.println (++i);//Prints 6system.out.println (i++);//Prints 7system.out.println (i);
4. Relational operators
= = Judgment Equality (the base type is judged by the value, and the reference type determines equality based on the address referenced by the object)! = is not judged equal to (IBID.) > Greater than>= greater than or Equa L to< less than<= less than or equal to
The above relational operators are typically used as a base type comparison, and object comparisons typically use the Equals method of the object.
5. Conditional operators
&& and
|| Or
int value1 = 1;int value2 = 2;if ((value1 = = 1) && (value2 = 2)) System.out.println ("value1 is 1 and value2 are 2 "); if ((value1 = = 1) | | (value2 = = 1)) System.out.println ("value1 is 1 OR value2 is 1");
6. Type detection
instanceof
Used to determine whether an instance is an instance of a class (a class or subclass of a class or an interface ) .
Class instanceofdemo { public static void main (String[] args) { parent obj1 = new parent (); parent obj2 = new child (); system.out.println ("obj1 instanceof parent: " + (obj1 instanceof parent)); system.out.println ("obj1 instanceof child: " + (obj1 instanceof Child)); system.out.println ("obj1 instanceof myinterface: " + (obj1 Instanceof myinterface)), &Nbsp; system.out.println ("obj2 instanceof parent: " + (obj2 instanceof Parent)); system.out.println ("Obj2 instanceof child: " + (obj2 instanceof child)); system.out.println ("obj2 instanceof myinterface: " + (obj2 Instanceof myinterface)); }} class parent {}class child extends parent implements myinterface {}interface myinterface {}
Output:
Obj1 instanceof parent:trueobj1 instanceof child:falseobj1 instanceof myinterface:falseobj2 instanceof parent:trueobj2 instanceof Child:trueobj2 instanceof Myinterface:true
7. Displacement operator
<< left-shift arithmetic >> right-shift operation >>> unsigned right-shift operation & Bitwise AND ^ Bitwise XOR | Bitwise OR ~ bitwise inverse (non)
Learn Java-chapter 2 operator (Operator)