第二三周总结

20182305 2019-2020-1 《数据结构与面向对象程序设计》第二、三周学习总结

教材学习内容总结

这两周的教材学习主要学习Java语言的数据类型和表达式,类和对象。包括如何设置变量、输入数据,使用+连接字符串,对变量进行赋值、计算操,强制改变数据类型。通过使用Rondom类生成随机数、格式化输出。并且综合运用这些编写简单的程序例如计算器、随机程序。

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

  • 问题1:print和println的区别;
  • 问题1解决方案:println会在输出后自动换行,作用大致等同于print+\n,但是print后可以使用\t、\r来输出不同的格式。综合使用更灵活,功能更强大。
  • 问题2:分清char和string类型使用中的区别;
  • 问题2解决方案:char为字符型,而string为字符串型。最大的区别在于字符串的最后有"\0"结尾。所以在使用 char = string.charAt(int)方法时,如果误将char打成string就会因为类型不兼容而报错。
  • 问题3:不理解类与方法之间的关系;
  • 问题3解决方案:通过查询资料和阅读教科书,我渐渐理解了类与方法间的包含关系,也明白了调用类中方法的途径(例如:Math.PI、Die.roll);

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

  • 问题1:在做书上题的时候出现除法运算后输出结果缺少小数部分的错误。
  • 问题1解决方案:检查后发现是我将aver = (float)(a+b+c)/ 3 ;错写成 aver = (float)((a+b+c)/3);导致输出结果小数位全为0而不是正确结果。
  • 问题2:使用Scanner类输入数据时发生错误,提示InputMismatchException。
  • 问题2解决方案:原来是输入类型与方法不匹配,将输入语句修改成与变量类型对应的即可。
  • 问题3:在做书上题PP3.1时,编译发生报错:
  • 问题3解决方法::变量b为char型为字符型,而a为string型为字符串型。区别在于字符串的最后有"\0"结尾,而字符型没有,所以charAt时只返回一个字符并不满足字符串以"\0"结尾的定义,于是乎就会出错。

代码托管

上周考试错题总结

  • 错题一:The word println is a(n) (单词println是一个)

A . method (方法)

B . reserved word (保留字)

C . variable (变量)

D . class (类)

E . String (字符串)

  • 原因:println是System.out.中的一个方法,而不是一个保留字。所以这题选A而不是E。
  • 错题二:What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? (如果x和y是int类型的数值,x=10,y=5,那么语句System.out.println(x+y);的输出是什么?)

A . 15

B . 105

C . 10 5

D . x+y

E . An error since neither x nor y is a String (因x和y都不是字符串而引起的一个错误)

  • 原因只有当println后括号里有双引号包括的字符串,即输出字符串时使用+才会将数据类型从数字自动转换为字符串输出。现在括号里没有字符串,直接输出x+y的计算结果, =15。
  • 错题三:
    If you want to store into the String name the value "George Bush", you would do which statement? (如果你想把"George Bush"这个值存储为字符串类型的名字,你会执行那条语句?)

A . String name = "George Bush";

B . String name = new String("George Bush");

C . String name = "George" + " " + "Bush";

D . String name = new String("George" + " " + "Bush");

E . Any of the above would work (上述都可以完成)

  • 原因,仔细看书之后就会发现,这些定义方法最后的结果其实是一样的。只是操作上略有简繁区别。
  • 错题四:What value will z have if we execute the following assignment statement?
    int z = 50 / 10.00; (如果我们执行下面的赋值语句,z将得到什么值?)

A . 5

B . 5.0

C . 50

D . 10

E . none of the above, a run-time error arises because z is an int and 50 / 10.00 is not (以上皆错,因z是一个整型数而50 / 10.00不是,会产生运行时错误)

  • 原因:50/10.00的结果为小数,而z的数据类型为整形,无法保存小数。
  • 错题五: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创建的变量在整个程序运行过程中无法被更改,更有利于程序稳定运行。
  • 错题六:Java is a strongly typed language. What is meant by "strongly typed"? (Java是一种强类型语言。“强类型”指的是什么?)

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 (变量存在于程序中时允许改变类型,但只能缩窄转换)

  • 错题七:A variable of type boolean will store either a 0 or a 1. (Boolean类型的变量将被存储为0或1)

A . true

B . false

  • 原因:在Java中,Boolean变量只有两个值:true、false,而不是0、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--;

  • 原因:因为语言问题,没能准确理解题意。
  • 错题九: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

  • 原因:对于字符型比较可以使用 > , < , == 等符号,但是对于字符串的比较只能用compare()这样的方法。

结对学习同学博客(20182327)

  • 博客中值得学习的或问题:

    • 分点分章节总结学习内容,全面、真实的写出了自己这两周的学习情况。
    • 添加了大量图片,这样有助于记录自己的学习过程、代码出错的情况,便于后续学习纠错总结。也可以更好的总结这一周的学习情况。
  • 代码中值得学习的或问题:

    • 添加的插件可以自动生成文件头,很方便。
  • 基于评分标准,我给本博客打分:11分。得分情况如下:正确使用Markdown语法+1.教材学习中的问题和解决过程+2.代码调试中的问题和解决过程+2.感想,体会不假大空+1.错题学习深入+1.点评认真,能指出博客和代码中的问题+1.结对学习情况真实可信+1.课后题有验证+1,进度条有记录+1.

点评过的同学博客和代码


学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 10000行 30篇 400小时
第一周 200/200 2/2 17/17
第二、三周 556/756 3/5 31/48 明白了类与方法的关系,对Java编程的思想的了解有了一些进步
  • 计划学习时间:35小时

  • 实际学习时间:31小时

posted @ 2019-09-22 14:12  20182305孙铭泽  阅读(333)  评论(0编辑  收藏  举报