java-based operator Syntax 2 ---

1. The basic usage of arithmetic operators!

  • What is operator
    symbols constant and variable operating called operators
  • Operator classification
    arithmetic operators + , - , * , / , % , ++ , --
    assignment operators =, +=,-=,*=,/=,%=
    Comparison Operators > < >= <= == != instanceof
    Logical Operators && || !
    Bitwise & | ^ ~ >> << >>>
    ternary operator?:
    Precautions:
    a: integer division can only get integer. If you want a decimal, use floating-point
    b: / acquired business is,% acquisition of the remainder of the division is operating division operation
    symbol% result of the operation, depending on the symbol on the left is involved in computing

2. Arithmetic operators ++ and - - Usage!

  • ++ - operator effect
    from plus (+) from the minus (-) operation
    +: increase since. The original data + 1
    -: decrement. The original data -1
  • Demo Case
    a: alone:
    in front of and behind the same effect as the operand.
    B: Use involved in computing:
    in front of the operands, the first increment or decrement, and then participate in operation.
    Operand placed behind the first operation involved in, and then increment or decrement.

	int a = 10;
	int b = 10;
	int c = 10;

	a = b++;
	c = --a;
	b = ++a;
	a = c--;
	
	/*结果
	a=9
	b=10
	c=8*/

	
	int x = 4;
	int y = (x++) + (++x) + (x*10);
	
	//x=6 , y=70

3. Basic use of the assignment operator!

A:赋值运算符有哪些
	=, +=,-=,*=,/=,%=
注意事项:
	a:基本的赋值运算符:=
		把=右边的数据赋值给左边。
		
	b:扩展的赋值运算符:+=,-=,*=,/=,%=
		+= 把左边和右边做加法,然后赋值给左边。
	c: 赋值运算符要求左边的数据必须是一个变量

4. The basic usage of relational operators and Notes

A:关系运算符有哪些
	== ,!= , < , > , <= , >= , instanceof(后面讲解)
注意事项:
	无论你的操作是简单还是复杂,结果是boolean类型。
	"=="不能写成"="。

The basic use of logical operators

A:逻辑运算符有哪些
	&(并且) , |(或者) , !(非) , ^(异或) , &&(短路与) , ||(短路或)
注意事项:
	a:逻辑运算符一般用于连接boolean类型的表达式或者值。
		在Java中我们要表示一个数大于3并且小于6 ,不可以写成3<x<6,应该写成 x>3 & x<6 。
	b:表达式:就是用运算符把常量或者变量连接起来的符合java语法的式子。
		算术表达式:a + b
		关系表达式:a == b
B:结论:
	&逻辑与:有false则false。
	|逻辑或:有true则true。
	^逻辑异或:相同为false,不同为true。
		举例:情侣关系。男男,男女,女男,女女
	!逻辑非:非false则true,非true则false。
		特点:偶数个不改变本身。

6. The logical operators && and & distinction

A:案例演示
	&&和&的区别?
		a:最终结果一样。
		b:&&具有短路效果。左边是false,右边不执行。
B:同理||和|的区别
C:开发中常用
	&&,||,!

7. The basic usage bitwise operator

  • What bitwise
    & (and), | (or), ^ (exclusive or) ~ (bitwise), << (shift left), >> (shift right), >>> (unsigned Right shift)
    Note: bit operation is carried out directly on the two's complement arithmetic.

Usage 1

&:有0则0
|:有1则1
^:相同则0,不同则1
~:按位取反 0变1 1变0
^ Features: a different data is another data bit or two, the number itself is not altered

Usage 2

<<:左移 空位补0,被移除的高位丢弃。
>>:右移 被移位的二进制最高位是0,右移后,空缺位补0;最高位是1,高位补1。
>>>:无符号右移 被移位二进制最高位无论是0或者是1,空缺位都用0补。
Example:
<<: the left << data by, for example, the mobile power of 2 << 3 10 10 Results 2 ^ 3 = 80 *
>>: the data by moving to the left >> power of 2, for example, 40> > 40 results 3/2 ^ 3 = 5

8. The basic usage of the ternary operator

  • Three yuan (trinocular) operators format
    (relational expression)? Expression 1: Expression 2;
    int a=(10>20)?30:50;
    // a=50
    
  • Ternary operator implementation process
    calculated relational expressions, if true, the result of the operation is the expression 1;
    if false, the result of operation is the expression 2;

Package mechanism

1. Write down the domain name
2. To prevent naming conflicts
3.package
4.import

Published 39 original articles · won praise 1 · views 528

Guess you like

Origin blog.csdn.net/love_to_share/article/details/104095097
Recommended