"Reviewing the old and learning the new" JAVA foundation 2

Basic conditional statement

  1. switch statement, the matching code will be executed after the case is matched. If there is no break statement, the following statements will continue to be executed until the break is encountered and the program ends
    2.while loop
    ```js
  2. whie(){
    do something
    }
  3. do{
    //do something
    }whie()
    ```
  4. break ends the loop continuet skips the rest of the loop and executes the next loop
  5. The debug statement is run first and then debug
  6. Array, storing multiple data of the same type
    ```js
  7. Declaration:
    data type [] array name
    int[] array
    data type array name []
    int scores[]
  8. Allocate space specified length
    array=new int[6]
    Merge:
    int array[] =new int[] {1,2,3}
    Simple:
    int array[]={1,2,3}

6. 二维数组:js
int[][] array= new int[2][3]
2 rows and 2 columns

```

7. Function

定义:
访问修饰符 返回值类型 方法名(参数){
    方法体
}
访问修饰符:public+protectd+private 或者不写  
返回值类型 void没有 String/int等就需要return相应的数据  
eg:  
public int calcSum(){
    int a =5 ;
    int b =2;
    int c = a+b;
    return c
}
有函数的返回,则需要接收
public class HelloWorld{
    
    public static void main(String[] agrs){
       //类内部调用自己
        HelloWorld hello = new HelloWorld
        int c = calcSum()
    }
    public int calcSum(){
    int a =5 ;
    int b =2;
    int c = a+b;
    return c
}
}
  • When there are parameters, the data types and positions of the actual and formal parameters are required to correspond
  • Method overloading: function method with the same name and different parameters (position, number, etc.)

Guess you like

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