zoukankan      html  css  js  c++  java
  • 20172318 2017-2018-2 《程序设计与数据结构》第6周学习总结

    20172318 2017-2018-2 《程序设计与数据结构》第6周学习总结

    教材学习内容总结

    • 数组元素:具有N个值的数组索引为0~(N-1)
    • 声明和使用数组: int[] height = new int[length]
    • 对象数组:将对象作为元素如例8.5中Grade的对象数组grades,例8.8中DVD对象数组collection
    • 命令行实参:调用解释器执行程序时命令行所包含的数据
    • 可变长度参数表:通过使用某种特殊语法的形参数,使所定义的方法能接收任意个数的参数,并将参数自动存入数组以便在方法中进行处理
    • 二维数组与多维数组:二维数组可表示为一个索引值为行,另一个为列,三维数组可表示为长方体,以此类推,但四维以上很难用图形表示

    教材学习中的问题和解决过程

    代码调试中的问题和解决过程

    • 问题1:编写PP8.1的时候最后结果没有出现50这个数
    • 问题1解决方案:原来的代码为final int NMCHAS = 50;,后来改成final int NUMCHAS = 51;,0到50有51个数,刚开始没怎么注意
    • 问题2:原先我写8.5的时候,对于计算其中的函数我应用了设置一个方法运用了可变长度参数表来计算平均数和方差,但编译时出现了错误

    private static double mean(int ... list)
    {
    double result =0.0;
    if (list.length !=0)
    {
    int sum = 0;
    for (int num : list)
    sum += num;
    result = (double)sum/list.length;
    }
    return result;
    }
    private static double sd(int ... list)
    {
    double result=0.0;
    if (list.length !=0)
    {
    double sum = 0.0;
    for (int num :list)
    sum += (num-mean(list))(nummean(list));
    result=Math.sqrt(sum);
    }
    return result;
    }
    _

    • 问题2解决方案:将两个方法放在public class pp8_5{} 内,而不是放在main方法内
    • 问题3 还是上面的代码,由于之前没在同一个类中用main方法和定义其他方法,出现了无法从静态上下文中引用非静态方法 的错误
    • 问题3解决方案:将两个方法都设置成static静态方法

    代码托管

    上周考试错题总结

    • 错题1及原因,理解情况
      Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count;
      A . The condition short circuits and the assignment statement is not executed
      B . The condition short circuits and the assignment statement is executed without problem
      C . The condition does not short circuit causing a division by zero error
      D . The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error
      E . The condition will not compile because it uses improper syntax
      选A,if语句程序执行是从左到右的,if左边错误,不会判断右边,避免了除零出现错误,if判断为假,不会执行if里面的语句,因此不会出现计算max的第二个除零错误

    • 错题2及原因,理解情况
      The break statement does which of the following?
      A . ends the program
      B . transfers control out of the current control structure such as a loop or switch statement
      C . ends the current line of output, returning the cursor
      D . denotes the ending of a switch statement
      E . indicates the end of line when using System.out.print
      选B,之前我选了C后来发现C是说返回游标,英语翻译方面还得加强理解

    • 错题3及原因,理解情况
      If a switch statement is written that contains no break statements whatsoever,
      A . this is a syntax error and an appropriate error message will be generated
      B . each of the case clauses will be executed every time the switch statement is encountered
      C . this is equivalent to having the switch statement always take the default clause, if one is present
      D . this is not an error, but nothing within the switch statement ever will be executed
      E . none of the above
      选E,没有break会自动跳转到之后的case语句,所以这样写没什么问题

    • 错题4及原因,理解情况
      Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?
      for (int i=0;i<5;i++)
      x += i;
      A . 0
      B . 4
      C . 5
      D . 10
      E . 15
      选D,循环之后x=1+2+3+4=10

    • 错题5及原因,理解情况
      Given that s is a String, what does the following loop do?
      for (int j = s.length( ); j > 0; j--)
      System.out.print(s.charAt(j-1));
      A . it prints s out backwards
      B . it prints s out forwards
      C . it prints s out backwards after skipping the last character
      D . it prints s out backwards but does not print the 0th character
      E . it yields a run-time error because there is no character at s.charAt(j-1) for j = 0
      选A,结合这周的数组就很好理解了,从最后一个字符向前输出出来的结果和原来的字符串相反

    • 错题6及原因,理解情况
      Which of the following statements are true about Java loops?
      A . all three loop statements are functionally equivalent
      B . while loops and do loops are essentially the same; but while loops always execute at least once
      C . if you know the number of times that a loop is to be performed, the best loop statement to use is a while loop
      D . loops may be replaced by an appropriate combination of if-else and switch statements
      E . none of the above
      选A,三个循环理论上来说是等价的

    • 错题7及原因,理解情况
      Each case in a switch statement must terminate with a break statement.
      A . true
      B . false
      选B,break语句不存在的情况下会跳过这个case继续执行下一个

    • 错题8及原因,理解情况
      The following for-loop is an infinite loop.
      for (int j = 0; j < 1000; ) i++;
      A . true
      B . false
      选A,i的增加对j的大小不会有影响,这是个无限循环

    • 错题9及原因,理解情况
      The following loop is syntactically valid.
      for (int j = 0; j < 1000; j++) j--;
      A . true
      B . false
      选B,会不断重复增加减少的过程,循环不会终止

    点评模板:

    • 博客中值得学习的或问题:
      • 博客:图片比较少,对问题反映不直观
      • 对8.5研究比较深刻
    • 代码中值得学习的或问题:
      • 代码比较简洁,使用了与大多同学不同的方法

    点评过的同学博客和代码

    • 本周结对学习情况
      • 20172312
      • 结对学习内容
      • 对课本内容的总结

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 5000行 30篇 400小时
    第一周 128/128 1/1 12/12
    第二周 212/340 1/2 18/30
    第三周 206/546 1/3 20/50
    第四周 483/1029 2/5 40/90
    第五周 633/1662 1/6 30/120
    第六周 560/2222 1/7 20/140

    参考资料

  • 相关阅读:
    【转】谈谈 JVM 内部锁升级过程
    TCP 和 UDP 协议简介
    《分布式系统原理介绍》读书笔记
    Paxos 协议简单介绍
    Lease 机制和 Quorum 机制
    HBase 学习二(最佳实践).
    HBase 学习一(基础入门).
    Spring 事务介绍
    《MySQL技术内幕:InnoDB存储引擎》读书笔记.
    数据库事务简介.
  • 原文地址:https://www.cnblogs.com/m1sty/p/8848809.html
Copyright © 2011-2022 走看看