zoukankan      html  css  js  c++  java
  • Homework2

    1: In the first program, the fault is that it misses the first element of the array. Since when i equals to 0, the for loop stopped, but  the program should check out each of the element in the array.  If the first element equals to y, the answer should be 0 instead of -1. So the i>0 should change to i>=0

        In the second program, the fault is that it actually obtains the position of the first zero element. This is mainly because the index i starts from 0, instead of the length-1, and as it pluses one in each for loop, it would finally found the first zero in the array rather than the last one.

    2: In first program, the test case is that x = null y could be a random number,which could throw the exception and do not execute the fault

      In the second program, the test case is that x = null, the reason is the same as the first statement.

    3: In the first program, the test case is the array x = [2,4,5,6,5,3] y = 5, The answer is four which is correct.And the i don't need to be equal  to 0, that the error state is not showed.

        In the second program, the test case is the array x = [3,4,2,3,1,5,0] The answer is 6 which is correct. Since if the answer is the length-1 the answer must be right.

    4: In the first program the test case is the array x = [3,2,4,5,2,3] y = 6. The answer is -1 since there is no 6 among the elements of the array, but the for loop actually does not reach every element since it miss the first element. However, it should not be regarded as a failure, as the final answer is right.

        In the second program, the test case is that the array x = [2,3,2,4,0,4,3]. The final answer is 4 which is right, but since the i does not start from the length of the array minus one, but from 0, there exists a risk that after the first 0, a few zeros may follow. Therefore, it can show the error of the program.

  • 相关阅读:
    全站仪定向距离差 方向不差 这样敢放线吗
    关于老王
    cad巧用插件自定义填充图形
    老王教你永不会错的测量坐标方位角计算方法
    jqgrid 点击列头的超链接或按钮时,不触发列排序事件
    jqgrid 将列头设置为超链接或按钮
    jqgrid 设置隔行换色
    jqgrid 设置行编辑为本地端编辑状态
    jqgrid 让隐藏的列在编辑状态时出现且可编辑
    jqgrid 设置编辑行中的某列为下拉选择项
  • 原文地址:https://www.cnblogs.com/pzyskytree/p/5248440.html
Copyright © 2011-2022 走看看