zoukankan      html  css  js  c++  java
  • 单元测试

    简单的例子:

    查找list[]中的最大值:

      int Largest(int list[], int length);

    首份实现代码如下:

      int Largest(int list[], int length){

       int i,max;

       for(i = 0; i < (length – 1); i ++ ) {

         if(list[i] > max) {

          max=list[i];

         }

      }

      return max;

      }

    修改后的代码:

    public class Main {
        public static void main(String args[]){
            int a[] = {4};
            int l = a.length;
            System.out.println(Largest(a,l));
        }
        static int Largest(int list[],int length){
            // 对函数的参数进行调试
            if(list == null || length != list.length)
                return 0;        
            int i,max = list[0];
            for(i = 1;i <= (length - 1);i++){
                if(list[i] > max){
                    max = list[i];
                }
            }
            return max;
        }
    
    }
  • 相关阅读:
    并查集
    关于一些位运算的小记
    用ST解决RMQ问题
    寒假作业_4
    H
    卢卡斯 组合数
    并查集
    G
    F
    E
  • 原文地址:https://www.cnblogs.com/twentytwo/p/4594285.html
Copyright © 2011-2022 走看看