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

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

    教材学习内容总结

    • 知道了相等性、关系与逻辑运算符的用法,尤其是==和赋值运算符=的区别,算数运算符优先级高于相等性和关系运算符。
    • if语句和if-else语句,以及if的嵌套,注意适当的缩进增强可读性,合理运用{ }来使用语句块和界定else属于哪一条if。
    • 数据的比较,特别的是浮点数的比较尽量少用==;数字在大写字母前,大写字母在小写字母前。
    • 三种功能等价的循环语句while、do、for,do一定执行一次循环体,for用于知道需循环几次,for中break的重要性。
    • 避免无限循环。
    • 用于管理对象集的ArrayList类,处理相关的一组元素的迭代器。

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

    • 问题1:if的缩进格式以及大括号的使用。
    • 问题1解决方案:自己仿造书上编写了一些程序,来实验它们的用法,缩进格式对程序没有影响只是为了理解容易,大括号对循环的作用很大,改变循环的内容。
    • 问题2:迭代器的意义,以及hasNext()的用法。
    • 问题2解决方案:看完书上的例题并不能完全理解,之后又学习了下一章的for-each,再练习了5.5的自测题,勉强弄懂了。
    • 问题3:== 和 eqaul的用法和区别。
    • 问题3解决方案:相等性运算符和关系运算符可用来比较字符,但是不可以用来比较字符串。 ==:比较的是两个字符串内存地址的数值是否相等,属于数值比较;equals():比较的是两个字符串的内容,属于内容比较。以后进行字符串相等判断的时候都使用.equals()。

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

    • 问题1:一些类的方法使用不熟练,比如这里整形和字符串之间的转换。

    • 问题1解决方案:按照书上的例题,自己重新设计一些简单的程序单独实验这些方法的用法。

    • 问题2:忘记了字符串和ArrayList引索是从0开始排序的,在使用比如charAT()、add(E obj)这样的方法总会出现这样的错误提示

    • 问题2解决方案:当时一直没能发现为什么错了,不断修改各个部分进行尝试最后才找到错误。

    • 问题3:在if的嵌套里面很容易犯错,比如用错了大括号或者else对应了错误的if

    • 问题3解决方案:使用正确的缩进格式很有必要,在检查程序时可以方便更改。

    • 问题4:在循环语句里,一些变量赋值的位置不对,一些变量该在循环之外赋值,有些应该随着循环不断改变

    • 问题4解决方案:在编写循环体之前应该有明确的思路,考虑好变量的使用位置,在合适的位置进行声明、赋值。

    代码托管

    上周考试错题总结

    • 错题1
      Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
      A . if (x > 0) x++;
      else x--;
      B . if (x > 0) x++;
      else if (x < 0) x--;
      C . if (x > 0) x++;
      if (x < 0) x--;
      else x = 0;
      D . if (x == 0) x = 0;
      else x++;
      x--;
      E . x++;
      x--;

    • 理解情况:当时对but leave x alone 的理解错了,所以选了C,应该是不管X了,所以应该是B。

    • 错题2
      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

    • 理解情况:因为一个&&条件的左手边是假的,条件是短路的,所以右手边没有被评估。从而避免了零误差的可能除法。因为条件是错误的,语句Max=total/count没有执行,同样避免了零错误的潜在除法。所以不选D而是选A。

    • 错题3
      If x is an int where x = 1, what will x be after the following loop terminates?
      while (x < 100)
      x *= 2;
      A . 2
      B . 64
      C . 100
      D . 128
      E . none of the above, this is an infinite loop
      正确答案: D 你的答案: B

    • 理解情况:当X=64时仍然小于100,还会再执行一次。

    • 错题4
      Which of the following are true statements about check boxes?
      A . they may be checked or unchecked
      B . radio buttons are a special kind of check boxes
      C . they are Java components
      D . you can control whether or not they will be visible
      E . all of the above
      正确答案: E 你的答案: A

    • 理解情况:当时不知道复选框,后来仔细看书才知道都是对的。

    • 错题5
      In Java, selection statements consist of the if and if-else statements.
      A . true
      B . false
      正确答案: B 你的答案: A

    • 理解情况:还应该有switch语句。

    • 错题6
      An if statement may or may not have an else clause, but an else clause must be part of an if statement.
      A . true
      B . false
      正确答案: A 你的答案: B

    • 理解情况:java允许if语句或if-else语句。但else只能作为if语句的一部分。

    • 错题7
      The following for-loop is an infinite loop.
      for (int j = 0; j < 1000; ) i++;
      A . true
      B . false
      正确答案: A 你的答案: B

    • 理解情况:此循环将J初始化为0,并将其与1000进行比较,但在每次循环迭代后不会更改J。实际上,当值太大而无法存储在内存中时,循环最终将以运行时错误结束,但逻辑上这是一个无限循环。

    • 错题8
      In Java, it is possible to create an infinite loop out of while and do loops, but not for-loops.
      A . true
      B . false
      正确答案: B 你的答案: A

    • 理解情况:这是真的,而while和do循环可以是无限循环,但for循环可以是无限循环。这在许多其他编程语言中都不是真的,因为for-loops有一个集的起点和结束点,但是java for-loops比大多数其他语言的for-loops灵活得多。

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 5000行 30篇 400小时
    第一周 189/189 1/1 18/18
    第二周 250/439 2/3 21/39
    第三周 437/876 3/6 25/64
    第四周 659/1535 2/8 31/95
    第五周 647/2182 1/9 30/125

    参考资料

  • 相关阅读:
    通过数据库查看EBS的登录地址
    重启redis报错:Waiting for Redis to shutdown
    Tomcat8启动报there was insufficient free space available after evicting expired cache entries
    EBS安装过程报错,oracle.apps.fnd.txk.config.ProcessStateException: FileSys OS COMMAND Failed : Exit=2 See log for details.
    CentOS系统将UTC时间修改为CST时间
    Tomcat启动时报错,Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext
    LICEcap 录制Gif动画
    Java 8 Optional In Depth
    IntelliJ IDEA推荐插件
    Java 8 – Convert Map to LIST
  • 原文地址:https://www.cnblogs.com/N-idhogg/p/8779195.html
Copyright © 2011-2022 走看看