Java knowledge point sorting: Chapter 2 Java basic knowledge sorting

1. Operators : Mathematical operators    + - * / % =

Comparison operators    > ,< , >,= ,<,= , != ,==;

Incrementing and decrementing      ++, --

Logical operators    & ,| ,! , && , ||;

Conditional ( ternary ) operator    a>b?a:b

 

a. Mathematical operators: the closure of operations ( the closure of complement operations ), the closure of java operations is the closure of complement operations

  For example , the final result of a value operation of type int is type int .

b. Operation rules in java

Participating operations of the same type ( may require automatic type conversion )

               Returns the same type:

The three types of byte, short, and char are representations in java , and they are operated according to int at the bottom layer  .

 Summary :

1. In the  + - * operation, the main focus is on the type of operation, and the problem of overflow

2. The division operation is an integer division .

3. Surplus :

    The remainder of 0 for any number is 0.

   modulo a fixed value, the result is a periodic function

    (n++%3)

   The remainder of a negative number is a negative number

   The remainder of a positive number is a positive number

c . Self-increase and self-decrease

    ++  --

   Operator ++  that increments ( decrements ) the current variable by itself

     int a ;

    Before ++++ a;

    post ++a++;

            

    From the ++ expression itself:

      There is no difference between before and after ++ ,

      are given to the current variable

      self increase 1

    From the whole operation expression:

     a++: first set the value of a as the value of this a++ expression, then increment a by 1

     ++a: first add 1 to the value of a, and then use it as the value of the ++a expression to participate in the operation

  d.  Logical expression:

Short circuit with &&   

 ①&&②

 When condition is false ,

 Condition is not executed and is short-circuited

                       short circuit or ||

                      ①||②

When condition is true ,

Condition is not executed and is short-circuited

          e. Ternary operator:

logical expression (true/false) ? expression1 : expression2

           Decide to execute expression 1 according to the result of the logical expression

or expression 2

           true : expression1 _

false: expression 2

2. Branch flow control statement:

        1. Branch flow control statement

a.if

      1.  if ( condition ) { code body }

      通过判断条件的true/false,来决定是否执行{}.  如果为true,则执行,为false,不执行

                 2.  if(条件){//条件为true}else{//条件为false}

      通过判断条件的true/false,来决定执行哪个大括号中的代码.

      如果为true,执行if后面的{}

      如果为false,执行else后面的{}

                 3.  if(条件){

      }else if(条件){ 

      }.....{ 

      }else{ 

      }

      if必须要出现,else if可有0-n个,else可有0-1个。

                 通过判断每个分支的条件,如果条件为true. 则执行对应的{}

      当有一个条件为true后,其他的分支不再判断.如果所有的条件判断都为false,则执行else 

b.switch case

      switch(整数表达式){

case 条件1

//代码

break;

case 条件2

case 条件3

...........

case 条件n:

default:

  }

  switch(表达式),只能是整数(int,byte,char,short),不能是long或者其他类型;

  case条件只能是整数(intbyte,short, char)常量(字面量),不能是变量及表达式;

             case条件的内容可以为空,如果为空,继续执行下面的代码;

             default表示如果没有满足case条件的其他 一切情况;

  在每一个case分支中,需要写break关键字。如果不写,会出现穿透现象.

         注:  穿透现象:下面所有的case分支不再进行判断直接执行.

2.循环控制

循环:重复去做某一些事情。 

java中的循环: 

while(条件表达式){ //循环体}

            通过判断条件表达式的结果决定是否执行循环体.

 true:执行循环体, false:退出循环

int a = 3 ;

while(a>0){

System.out.println(a);

a--;

}

 一般来说,使用while循环的时候都是使用它的死循环。

while(true){ 

  //跳出循环的判断

  if(条件为true){

break;

  }

}

 do{//循环体}while(条件表达式),先执行循环体,后判断条件

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324705759&siteId=291194637