defer+recover机制处理错误

阅读 9

2024-06-19

题目:

定义一个方法,该方法能够找出三个整数中的最大值并返回。在主方法中调用方法测试执行。

我写的代码:

public static void main(String[] args) {
    Test test = new Test();
    int max = test.getMax(1,5,2);
    System.out.println(max);
}
public int getMax(int a,int b,int c){
    if (a > b){
        if (a > c){
            return a;
        }else {
            return c;
        }
    }else {
        if (b > c){
            return b;
        }else {
            return c;
        }
    }
}

代码有可能不是最优解答,如果有大佬也可以把更完美的代码发到评论区,或者给出优化的代码

精彩评论(0)

0 0 举报