# 20182328 2019-2020-1 《数据结构与面向对象程序设计》第2、3周学习总结

教材学习内容总结

第二章主要讲了java中基本数据类型和其转换,如何使用表达式,以及读入用户输入的方法
第三章主要是更详细地讲各种类的概念及使用,使用类与对象来进行各种复杂操作,还有枚举类型的概念

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

  • 问题1:不知道如何提取字符串的单个字母。
  • 问题1解决方案: 使用char.charAt()命令。
  • 问题2:π如何表达?
  • 问题2解决方案:调用Math类中Math.PI即可
  • ...

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

  • 问题1:输出代码有问题。

  • 问题1解决方案:圆括号里面不能有“,”必须用+把字符串和数值操作数连接起来。
  • 问题2:执行提取部分字符串命令时错误。

  • 问题2解决方案:命令String substring(int num1,int num2)错误,应为String.substring(int num1,int num2)。
  • 问题3:执行平方计算错误。

  • 问题3解决方法:命令输错,应为Math.pow(r,2)
  • 问题4:显示非法表达式

  • 问题4解决方法:应将常数放在计算开头。

代码托管

上周考试错题总结

  • 1、错题:In Java, "instantiation" means
    A .noticing the first time something is used
    B .creating a new object of the class
    C .creating a new alias to an existing object
    D .launching a method
    E .none of the above
    解析:“实例化”意味着创建对象的新实例,这是基本知识点。

2、错题:The String class' compareTo method
A .compares two string in a case-independent manner
B .yields true or false
C .yields 0 if the two strings are identical
D .returns 1 if the first string comes lexically before the second string
E .none of the above
解析:如果两个字符串相同,compareTo将生成0,-1如果第一个字符串在第二个字符串之前按字典顺序出现,则生成+1,如果第一个字符串在第二个字符串之后按字典顺序出现。
3、错题:These two ways of setting up a String yield identical results:

a) String string = new String(12345);

b) String string = new String("12345");
A .true
B .false
解析:没有接受数值参数的字符串构造函数的重载版本。

4、错题:Consider the following statement:
System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ________ lines of text (思考下面的语句,该语句将输出___行文本)
A .1
B .2
C .3
D .4
E .5
解析:转义序列插入制表符,但将光标留在同一行。转义序列会产生新行,以便在下一行输出“4 dinner”。转义序列导致回车(即,光标移回左边距),但由于它没有开始一个新行,“2night”在“4dinn”上输出,导致第二行看起来像“2night”。

5、错题:If you want to output the text "hi there", including the quote marks, which of the following could do that? (如果你想输出文本"hi there",包括引号在内,下面哪个语句可以做到?)
A .System.out.println("hi there");
B .System.out.println(""hi there"");
C .System.out.println(""hi there");
D .System.out.println(""hi there"");
E .none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output (无,不可能输出引号,因为它被用来标记字符串的开始和结束)
解析:”是一个转义序列,用于在字符串中放置引号,因此这里使用它来输出引号和字符串的其余部分。

6、错题:A cast is required in which of the following situations?
A .using charAt to take an element of a String and store it in a char
B .storing an int in a float
C .storing a float in a double
D .storing a float in an int
E .all of the above require casts
解析:对于a,charat返回一个char,因此没有问题。在b和c中,情况是扩大操作,采用较窄的类型,并将值存储在较宽的类型中。只有在d中,才会出现更宽类型存储在更窄类型中的情况,因此需要强制转换。

7、错题:If x is an int and y is a float, all of the following are legal except which assignment statement? (如果x是一个int类型的数,y是一个float类型的数,下面所有赋值语句中哪个不合法?)
A .y = x;
B .x = y;
C .y = (float) x;
D .x = (int) y;
E .all of the above are legal (以上全部合法)
解析:由于X是int,除非浮点是int型的,否则它不能除浮点。B中的赋值语句中没有明确的抛出。在A中,不需要一个抛出,因为浮点(y)可以接受int值(x),而在c和d中,显式抛出使它们合法。

8、In order to create a constant, you would use which of the following Java reserved words? (为了创建一个常量,你会使用下列Java保留字中的哪一个?)
A .private
B .static
C .int
D .final
E .class
解析:保留字final表示这是将存储在此变量中的最终值,因此使其不可更改或为常量。常量可以是int类型,常量也可以是任何其他类型。它是最后一个保留字,使值不可更改。

9、错题:Java is a strongly typed language. What is meant by "strongly typed"?
A .Every variable must have an associated type before you can use it
B .Variables can be used without declaring their type
C .Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type
D .Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be
E .Variables are allowed to change types during their existence in the program but only if the change is to a narrower type
解析:强类型是一种编程语言的属性,通过它,变量的类型在变量存在期间不会改变,并且存储在该变量中的任何值都是该类型的。强类型是重要的原因是它保证了成功编译的程序不会有与声明变量的类型的滥用相关联的运行时错误。

10、错题:The values of (double) 5 / 2 and (double) (5 / 2) are identical. ((double) 5 / 2和(double) (5 / 2)的值是相同的。)
A .true
B .false
解析:在第一个表达式中,(double)强制转换应用于int 5,将其更改为double值5.0。然后计算5.0/2,得到双倍值2.5。在第二个表达式中,首先执行int除法,得到值2。然后将2更改为double,得到double值2.0。

11、错题:Every Interator
A .has a hasNext( ) method
B .has a hasFirst( ) method
C .has a hasNextInt( ) method
D .has a isEmpty( ) method
E .none of the above
解析:每个迭代器都有一个hasNext()方法,如果有迭代元素尚未处理,则该方法为true。每个迭代器也有一个next()方法,该方法传递下一个元素以进行处理。

12、错题:In order to compare int, float and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo( ), equals( ) and equalsIgnoreCase( ).
A .true
B .false
解析:你也可以直接比较char变量,使用<,>,=,!=,<=,>=,但必须使用compareTo()、equals()和equalSignoreCase()进行任何字符串比较。

结对及互评

评分标准

  • 基于评分标准,我给本博客打分:14分。得分情况如下:
  1. 正确使用Markdown语法(加1分):
  2. 模板中的要素齐全(加1分)
  3. 教材学习中的问题和解决过程,加4分
  4. 代码调试中的问题和解决过程,加4分
  5. 其他加分(加4分)

    点评模板:

  • 博客中值得学习的或问题:
    • 内容详实且精简
    • 问题充分且已解决
    • 有配图
  • 代码中值得学习的或问题:
    • 正确且简练
    • 方法多样很值得学习
    • ...
  • 参考示例

点评过的同学博客和代码

其他(感悟、思考等,可选)

1、这两周学的内容比较多,有点跟不上,但是多抽出点空闲时间还是能够学到更多东西的,第四周,我尽量抽出更多的时间去敲代码。
2、尽量多看课本,课本上的内容很详实,有不会的先看课本,再从网上搜。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 200/200 2/2 20/20
第二周 300/500 2/4 18/38
第三周 500/1000 3/7 22/60
第四周 300/1300 2/9 30/90

参考:软件工程软件的估计为什么这么难软件工程 估计方法

  • 计划学习时间:30小时

  • 实际学习时间:25小时

参考资料

猜你喜欢

转载自www.cnblogs.com/monsterhunter/p/11569847.html