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

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

教材学习内容总结

  • 字符串的使用,连接,转义字符
  • 数据类型,强制转换
  • 布尔(Boolean)类型
  • 读入数据
  • improt声明
  • String,Random,Math,枚举类
  • 格式化输出
  • 包装类

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

  • 问题1:包装类有什么用?
  • 问题1解决方案:基本数据类型之间的相互转换不是都可以制动转换的,而你强制转换又会出问题,比如String类型的转换为int类型的,为了方便用户就提供了相应的包装类。有时候一个函数需要传递一个Object的变量 而你想传递int类型的进去显然不行,就用到了包装类。

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

  • 问题1:提示没有找到类Scanner
  • 问题1解决方案:import java.util.Scanner;的S要大写
  • 问题2:姓氏只返回了四个字母
  • 问题2解决方案:substring(a,b)返回的是a~b-1位置的字符
  • 问题3:若随机数生成了0,就不会输出
  • 问题3解决方案:用printf输出,不够位数用if判断补0

代码托管

上周考试错题总结

  • 思考下面的语句,该语句将输出___行文本
System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");

答案:2。\r是回车,回到当前行行首。

  • 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 (变量存在于程序中时允许改变类型,但只能缩窄转换)
答案:C。定义变量时必须声明类型。

  • 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--;

答案:B。题目说的如果是0就不操作,而C做了操作。

  • What happens if you attempt to use a variable before it has been initialized?

A . A syntax error may be generated by the compiler
B . A runtime error may occur during execution
C . A "garbage" or "uninitialized" value will be used in the computation
D . A value of zero is used if a variable has not been initialized
E . Answers A and B are correct
答案:E。按照题目的意思,出现编译错误也可以运行。

  • Which of the following will yield a pseudorandom number in the range [ -5, +5 ) given the following:

Random gen = new Random( );

A . gen.nextFloat( ) * 5
B . gen.nextFloat( ) * 10 - 5
C . gen.nextFloat( ) * 5 - 10
D . gen.nextInt( ) * 10 - 5
E . gen.nextInt(10) - 5
答案:B。看错。

  • 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
答案:C。没看懂identical的意思。

  • These two ways of setting up a String yield identical results:

a) String string = new String("123.45");

b) String string = "" + 123.45;

A . true
B . false
答案:A。可以用双引号提示程序是一个字符串,然后用加号对字符串连接。

  • You may use the String replace( ) method to remove characters from a String.
    A . true
    B . false
    答案:B。会替换为空格,不是删。
  • If you need to import not only the top-level of a package, but all its secondary levels as well, you should write: import package..;

A . true
B . false
答案:B。声明范围太广了,只能声明倒数第二级的。

结对及互评

  • 博客中值得学习的或问题:
    • 代码问题的解决是自己想的,没有百度或者问
    • 错题分析有自己的见解
  • 代码中值得学习的或问题:
    • 用C语言的方法解决Java的问题
    • 重复的直接复制粘贴
  • 基于评分标准,我给本博客打分:12分。得分情况如下:
    • 正确使用Markdown语法(加1分)
    • 模板中的要素齐全(加1分)
    • 教材学习中的问题和解决过程, 一个问题加1分
    • 代码调试中的问题和解决过程, 三个问题加3分
    • 本周有效代码超过300分行的(加2分)
    • 排版精美的加一分
    • 代码Commit Message规范的加1分
    • 有动手写新代码的加1分
    • 结对学习情况真实可信的加1分

点评过的同学博客和代码

  • 本周结对学习情况
    • 20182331
    • 结对学习内容
      • 重装Linux
      • 替换vimrc
      • 切换源
      • 比较C语言和Java
      • 帮助分析错误

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 10000行 30篇 400小时
第一周 138/138 2/2 25/25 学会写和上传代码,会编简单的输出程序
第二周 118/256 1/3 30/55 起文件名不能太长
第三周 868/1124 2/5 35/90 Java类里面的方法和C语言的函数很像

参考资料

posted @ 2019-09-22 10:10  蓝火BlueFlameAshe  阅读(200)  评论(0编辑  收藏  举报