0
点赞
收藏
分享

微信扫一扫

defer+recover机制处理错误

婉殇成长笔记 2024-06-19 阅读 7

题目:

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

我写的代码:

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 条评论