《温故而知新》JAVA基础二

基本条件语句

  1. switch语句,case匹配后会执行匹配的代码,如果没有break语句,会继续执行后面的语句,直到遇到break和程序结束为止
    2.while循环
    ```js
  2. whie(){
    do something
    }
  3. do{
    //do something
    }whie()
    ```
  4. break结束循环 continuet跳过本次循环剩下的语句,执行下一次的循环
  5. 调试语句 先打点 后debug
  6. 数组,存放类型相同的多个数据
    ```js
  7. 申明:
    数据类型[] 数组名
    int[] array
    数据类型 数组名[]
    int scores[]
  8. 分配空间 指定长度
    array=new int[6]
    合并:
    int array[] =new int[] {1,2,3}
    简约:
    int array[]={1,2,3}

6. 二维数组:js
int[][] array= new int[2][3]
2行2列

```

7.函数

定义:
访问修饰符 返回值类型 方法名(参数){
    方法体
}
访问修饰符: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
}
}
  • 当带参数时候,需要实参和形参数据类型和位置对应
  • 方法重载:函数方法名称相同 参数不同(位置,个数等)

猜你喜欢

转载自www.cnblogs.com/allenxieyusheng/p/9015511.html