【1】源代码

 1 int disCount(int inputVal, int quantity, int yearToDate)
 2 {
 3     if (inputVal > 50)
 4     {
 5         inputVal -= 2;
 6     }
 7     if (quantity > 100)
 8     {
 9         inputVal -= 1;
10     }
11     if (yearToDate > 10000)
12     {
13         inputVal -= 4;
14     }
15     return inputVal;
16 }

【2】移除对参数的赋值动作

 1 // 以临时变量取代对参数的赋值动作
 2 int disCount(int inputVal, int quantity, int yearToDate)
 3 {
 4     int result = inputVal;
 5     if (inputVal > 50)
 6     {
 7         result -= 2;
 8     }
 9     if (quantity > 100)
10     {
11         result -= 1;
12     }
13     if (yearToDate > 10000)
14     {
15         result -= 4;
16     }
17     return result;
18 }

【3】总结

代码对一个参数进行赋值。以一个临时变量取代该参数的位置。

 

Good Good Study, Day Day Up.

顺序 选择 循环 总结

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-05-14
  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案