代码(if…else)->重构->重整思路上升到算法->记忆算法
int max = 0;
if(num1>num2) {
max = num1;
}else {
max = num2;
}
int max = 0;
if(num1>num2) {
max = num1;
}
if(!(num1>num2)) {
max = num2;
}
int max = num2;
if(num1>num2) {
max = num1;
}
if(!(num1>num2)) {
max = num2;
}
int max = num2;
if(num1>num2) {
max = num1;
}
public class R01MaxIf {
public static void main(String[] args) {int num1 = 10;
int num2 = 1;
//1.else->if
//2.修改初始化的值
//3.找重复,代码的问题
//4.去掉重复
//5.重构到算法
int max = num2;
if(num1>max) {
max = num1;
}
System.out.println(num1+“和”+num2+“最大的是”+max);
}
}
两个数比较大小:if..else重构if
最新推荐文章于 2022-10-10 16:14:16 发布