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

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

教材学习内容总结

第五章 条件判断与循环:

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

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

3、数据比较
一、数据比较所用的相关运算符:相等性运算符和关系运算符、逻辑运算符;
二、比较对象的不一样所用的方法也不一样:浮点数比较、字符比较;git

4、迭代器
一、迭代器对象的基本方法;
二、ArrayList类的用法;web

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

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

2、循环语句
一、do语句:与while类似,可是它是先执行后判断,至少会执行一次;
二、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,可是问题就来了,出现了这个错误:app

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

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)界面

相关文章
相关标签/搜索