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

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

    教材学习内容总结

    第五章 条件判断与循环:

    一、条件语句
    1、条件语句的内容:if语句、if-else语句和switch语句(此语句在第六章详细介绍其功能);
    2、if语句:由保留字if、紧随其后的布尔表达式及一条或一组语句构成;
    3、if-else语句:当我们希望当某个条件表达式的值为true时做的一件事情,为false时做的另外一件事情;

    二、循环语句
    1、循环语句的内容:while语句、do语句和for语句 (该章主要讲解while语句内容及其功能);
    2、while语句:当条件符合时,接着做下面的语句;不符合时,退出循环;

    三、数据比较
    1、数据比较所用的相关运算符:相等性运算符和关系运算符、逻辑运算符;
    2、比较对象的不同所用的方法也不同:浮点数比较、字符比较;

    四、迭代器
    1、迭代器对象的基本方法;
    2、ArrayList类的用法;

    第六章 其他条件判断与循环:

    一、条件语句
    1、switch语句内容: 其作用是进行判断选择;
    2、条件运算符:与if-else相似但不相同,通常书写为:“?:”;

    二、循环语句
    1、do语句:与while相似,但是它是先执行后判断,至少会执行一次;
    2、for语句:特别适用于循环执行前已经确切知道具体循环次数的情况;

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

    • 问题1:if和else必须要一一对应,以及必须以成对的形式出现吗?
    • 问题1的解决方案:在书中我看到了两段这样的代码
       if(num1<num2)
            if(num1<num3)
              min = num1;
            else
              min = num3;
       else
            if (num2<num3)
             min = num2;
            else
             min = num3;
    
    
       if(code == 'R')
           if(height <= 20)
              System.out.println("Situation Normal");
           else
              System.out.println("Bravo!");
    
    

    当时就有一点晕,但是按照逻辑分析,我认为没有错误,所以就按照上面两种敲了作业,其中就出现了问题,当我在利用第二种代码敲好我的作业pp5.3之后,编译以后没有错,而且可以正常输出。

    在我觉得的确可以这样写以后,我就按照这种方式编写了我的pp5.7,但是问题就来了,出现了这个错误:

    当时真的瞬间就傻了,就回头去检查pp5.3,发现依旧可以输出,最后发现没有加{},问题的根源就是pp5.7的时候需要加上“块”,因为里面不仅仅只有“XX++”了,还要输出,计算,问题的解决的依旧在书中也找到了:

    else子句会和它前面最近的没有匹配项的if语句相匹配。

    所以,虽然有时候不需要一一对应,但是要记住,else一定要管够,缺一不可。

    • 问题2:在进行数据比较的时候,当对象是分别是“int”和“String”的时候,利用“==”是否可以进行比较。比如,如果String类的字符类型刚好是整数,能否比较?
    • 问题2解决方法:我进行了实验,

    结果

    问题也就解决了。

    • 问题3:
      各个循环各自的特点是什么?
    • 问题3解决方案:
      引用书中的话进行解答:

    while循环和do循环的主要不同之处在于何时计算条件表达式的值。如果要让循环体至少执行一次,do循环通常是更好的选择。而对于while循环来说,如果表达式初始值为fales,则循环体一次都不会执行。

    当循环次数是确定的货是很容易计算时,通常使用for。

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

    • 问题1:在编写while练习题的时候,发生了一个所谓的无限循环,当时惊讶到我了,如图:

    • 问题1解决方法:
      就是因为while花括号没有放对位置,导致一直进行着死循环。

    • 问题2:在编写作业的时候,发现输出的语句跳了一个:

    检查代码:

    • 问题2解决方案:
      神奇的发现自己给while多打了一个“;”
      特别尴尬...

    • 问题3:
      在编写作业的时候,总是提示我输入的数字超出范围....

    • 问题3解决方案:
      分析了自己编写程序的每一句话,发现了问题,在这里:

    我定义的num3结果是输入字符串的字符个数,最后输入“666”告诉我“666>3,不行!”,最后把那个长度改正了,问题也就解决了。

    • 问题4 :
      在做12*12乘法表的时候,总是不能按照正确格式输出:

    • 问题4解决方案:
      简单来说,少了一行代码;
      具体来讲,少了哪一行呢;
      见下图:

    代码托管

    git出现了一次问题,删除了很多代码。
    commit格式还在学习当中,掌握马上修改。

    上周考试错题总结

    • 错题1:
      Which of the following reserved words in Java is used to create an instance of a class?
      A.class
      B.public
      C.public or private, either could be used
      D.import
      E.new

        正确答案: E 我的答案: C 
      

    原因:我理解成了创造类,编写类用哪一个,然后就没有理解,选择错误。

    • 错题2:
      In order to preserve encapsulation of an object, we would do all of the following except for which one?
      A.Make the instance data private
      B. Define the methods in the class to access and manipulate the instance data
      C. Make the methods of the class public
      D. Make the class final
      E. All of the above preserve encapsulation

         正确答案: D 我的答案: C
      

    原因:我做题有时候会忘记定义一个常量要用final,一般编程序的时候才有意识去想。

    • 错题3:
      If a method does not have a return statement, then
      A. it will produce a syntax error when compiled
      B. it must be a void method
      C. it cannot be called from outside the class that defined the method
      D. it must be defined to be a public method
      E. it must be an in, double, float or String method

        正确答案: B 我的答案: C 
      

    原因:我认为如果不能返回一个声明,它就无法在测试程序中输出出来,我觉得它就不能被调用。

    • 错题4:
      Consider a Rational class designed to represent rational numbers as a pair of nit’s, along with methods reduce (to reduce the rational to simplest form), god (to find the greatest common divisor of two nit’s), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and god methods be declared to be private.
      A. Because they will never be used
      B. Because they will only be called from methods inside of Rational
      C. Because they will only be called from the constructor of Rational
      D. Because they do not use any of Rationale’s instance data
      E. Because it is a typo and they should be declared as public

        正确答案: B 你的答案: C 
      

    原因:我在学习本章的时候就出现了概念性的错误,我以为方法是属于构造方法的,实际上它们是并列的。

    • 错题5:
      Consider a method defined with the header: public void foo (in a, in b). Which of the following method calls is legal?
      A. foo (0, 0.1);
      B. foo (0 / 1, 2 * 3);
      C. foo (0);
      D. foo ( );
      E. foo (1 + 2, 3 * 0.1);

        正确答案: B 你的答案: D 
      

    原因:看到int,与(0/2)比较感觉一个是整形变量,一个是浮点数,其实(0/2)=0吗?(扪心自问)

    • 错题6:
      Consider a method defined with the header: public void double foo (double x). Which of the following method calls is legal?
      A. double foo (0);
      B. double foo (0.555);
      C. double foo (0.1 + 0.2);
      D. double foo (0.1, 0.2);
      E. all of the above are legal except for D

        正确答案: E 你的答案: B 
      

    原因:这道题,纯属眼瞎,看题的时候,没有注意那个是逗号;

    • 错题7:
      The expressions that are passed to a method in an invocation are called
      A. actual parameters
      B. formal parameters
      C. formal arguments
      D. formals
      E. any of the above

        正确答案: A 你的答案: B 
      

    原因:典型的概念理解模糊,当时还是不够清楚形参和实参的具体概念。

    • 错题8:
      What happens if you declare a class constructor to have a void return type?
      A. You'll likely receive a syntax error
      B. The program will compile with a warning, but you'll get a runtime error
      C. There's nothing wrong with declaring a constructor to be void
      D. The class' default constructor will be used instead of the one you're declaring
      E. None of the above

        正确答案: A 你的答案: D 
      

    原因:这道题,老师重新讲了,答案是D,我对啦!

    • 错题9:
      Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
      A. true
      B. false

        正确答案: B 你的答案: A 
      

    原因:出现了和上上一题一样的错误。

    • 错题10:A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.
      A. true
      B. false

        正确答案: A 你的答案: B 
      

    原因:后来在书里给我找到了这句话的原句,每次都发现看书不仔细。

    • 错题11:
      During program development, software requirements specify
      A. how the program will accomplish the task
      B. what the task is that the program must perform
      C. how to divide the task into subtasks
      D. how to test the program when it is done
      E. all of the above

        正确答案: B 你的答案: E 
      

    原因:当时很单纯的以为,这种题不应该所有都有吗,最后发现这是一个坑。

    • 错题12:
      Which of the following methods is a static method? The class in which the method is defined is given in parentheses following the method name.
      A. equals (String)
      B. to Uppercase (String)
      C. sort (Math)
      D. format (Decimal Format)
      E. paint (Applet)

        正确答案: C 你的答案: B 
      

    原因:这道题忘记当时为什么选B,好像发现有一点看不懂,就随便编了一道。

    • 错题13:
      Inheritance through an extended (derived) class supports which of the following concepts?
      A. interfaces
      B. modular
      C. information hiding
      D. code reuse
      E. correctness

        正确答案: D 你的答案: A 
      

    原因:本来选的D,查单词的时候,点空白,点到了A,崩...

    • 错题14:
      Interface classes cannot be extended but classes that implement interfaces can be extended.
      A. true
      B. false

        正确答案: B 你的答案: A 
      

    原因:我理解概念正好与其相反了,上次上课,老师已经将讲过,纠正了自己的错误。

    • 错题15:
      All objects implement Comparable.
      A. true
      B. false

        正确答案: B 你的答案: A 
      

    原因;对概念的理解不清楚。

    • 错题16:
      Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
      A. true
      B. false

        正确答案: B 你的答案: A 
      

    原因:同某一道题,一模一样的。

    感悟

    • 发现现在越来越多的同学在给自己的博客添加一些好看的元素,我也在学习CSS,发现挺好玩的;
    • 现在连编辑文字结尾经常都用“;”结尾,感觉敲代码会敲出后遗症;
    • 越来越感觉到Java的魅力,晚上想要多敲会儿,但是,电脑不答应啊....(电量实在是太少了)
    • 这一周的作业大部分都由自己独立完成了,不像上几周,经常问舍友,问同学,也算自己的一点进步吧~!

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积)
    目标 5000行 30篇 400小时
    第一周 156/156 1/1 15/15
    第二周 217/371 1/2 20/35
    第三周 233/604 2/4 20/55
    第四周 1382/1986 1/5 35/90
    第五周 146/2196 1/6 25/115

    参考

    Java程序设计
    如何让博客变的悄悄好看
    蓝墨云
    一步一步教你自定义博客园(cnblog)界面

  • 相关阅读:
    List--使用List作为堆栈和队列
    Range的范围
    异常处理
    关于打印输出的一些方法
    关于set的unordered特性
    面向对象
    函数
    Linux中命令备份mysql形成文件
    局域网内Linux下开启ftp服务的“曲折路”和命令复习
    linux下的apache服务自启动的几种方式
  • 原文地址:https://www.cnblogs.com/qh45wangwenbin/p/8763025.html
Copyright © 2011-2022 走看看