回顾方法的定义

public class Demo01 {
//main 方法
public static void main(String[] args) {
}

修饰符 返回值类型 方法名(.....){
方法体
return 返回值;
}
**方法名**:注意规范 驼峰命名 见名知意
**参数列表**: (参数类型,参数名) ....可变长参数
**break**: 跳出switch 结束循环
**return**:结束方法 返回一个结果!(可能为空,可能为任意其他类型)
public String sayHello(){
    return "HelloWorld";
}
public void print(){
    return;
}

public int max(int a,int b){
return a>b ? a: b;//三元运算符
}

//异常

//数组下标越界:Arrayindexoutofbounds
public void readFile(String file) throws IOException {

}
}

猜你喜欢

转载自blog.csdn.net/qq_44499722/article/details/108474220