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

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

教材学习内容总结

第八章:数组

1、数组元素 一、访问数组的方式:“数组名[索引值];<span style="color:red">不能混淆索引值和存于该索引值位置的数据值。php

2、声明和使用数组 一、定义结构:int[ ] 数组名 = new int[索引值] 或者 int 数组名[ ]; 二、在全部的Java运算符中,索引运算符“[ ]”有最高的优先级; 三、检查数组边界的方法之一:利用length;例:numbers.length; 四、数组初始值表:各数据用逗号隔开,并以花括号({ })做为终结符;例:int[ ] scores = {1,2,3}; <span style="color:red">注:数组的长度是它可保存的个数,所以数组的最大索引值是(length-1);html

3、对象数组 一、一个数组能够有多个对象,每一个对象又由一组变量和使用这些变量的方法组成,而对象中的变量可能自己又是数组;git

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

  • 问题1:在学习例子8.3的时候,发现例题用到了char方法,其中有这样一段:
for (int ch = 0;ch<line.length();ch++)
        {
            current = line.charAt(ch);
            if (current>='A' && current<='Z')
                upper[current-'A']++;
            else
                if (current>='a' && current<='z')
                    lower[current-'a']++;
                else
                    other++;
        }

我忽然发现字符之间怎么能相减呢,并且是单引号,这是个啥呀,一整子恍惚......web

  • 问题1解决方案:果真如今属于学一部分,以前的知识就可能会忘记,仍是要时常温习, 原来最后查了char的用法,记起来它用的是ASCⅡ表... 编程

  • 问题2:有一句代码常常看见,可是不是很理解:数组

NumberFormat fmt = NumberFormat.getCurrencyInstance();
  • 问题2解决方案:在扔到百度上查阅,发现其叫作数字格式化: 数据结构

  • 问题3:在学习8.4命令行形参那个例题后,感受上是发现了新世界,由于一开始咱们就学习了他们的各部分<span style="color:red">(String[] args:从控制台接收参数)</span>.可是就是咱们一直死记忆的main方法的那一句app

public static void main(String[] args)

书中讲其实args就是一个数组,这就让我想,可不能够把它换成其余的呢?less

  • 问题3解决方法: 我实验过发现实际上是能够的,可是为何恰恰要写成args呢?可能那个造这个东西的叫args。。。 因而就继续进行解决:

发现网上有和我同样有疑问的..果真是约定俗成的。编程语言

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

  • 问题1:在敲完例题8.10之后,发现不能运行?蹦出来ArrayIndexOutOfBoundsException异常

  • 问题1解决方案:由于书里紧接着有这样一段话:

若是两个实参字符串都没有在命令行上提供,那么args数组将没有足够的元素,程序中对args数组的引用将致使抛出ArrayIndexOutOfBoundsException异常。

可是如今就有一个问题,我该在哪里输入这个实参字符串呢?

我尝试了把args定义拿出来:

结果呢?

仍是不对..哪里出问题了呢? 忽然意识到好像应该有两个值,因而就再给他加一个:

结果呢?

终于成功了... 可是如今还有一个问题,书本上讲的是在命令行里输入,可是我这个就是在程序里输入,仍是有问题: 有什么问题呢?其实就是ieal不具有输入命令行的功能,因此输入不了,就用虚拟机:

其实也就解决了。

代码托管

上周考试错题总结

  • 错题1 Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? If (count! = 0 && total / count > max) max = total / count; A. The condition short circuits and the assignment statement is not executed B. The condition short circuits and the assignment statement is executed without problem C. The condition does not short circuit causing a division by zero error D. The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error E. The condition will not compile because it uses improper syntax

解析:因为count为0,(count!= 0)为false。因为&&条件的左侧为假,所以条件短路,所以不判断右侧。所以,避免了零偏差的潜在除法。因为条件为false,所以不会执行max = total / count语句,从而避免可能的零点错误除法。

缘由:我选择D的缘由认为判断语句仍是能够输出的,可是结果不是这个样子,直接中断。

正确答案: A 个人答案: D
  • 错题2 If a break occurs within the innermost loop of a nested loop that is three levels deep A. when the break is encountered just the innermost loop is "broken" B. when the break is encountered, all loops are "broken" and execution continues from after the while statement (in our example) C. when the break is encountered, all but the outermost loops are broken, and execution continues from the next iteration of the while loop (in our example) D. this is a syntax error unless there are break or continue statements at each loop level E. none of the above

解析:最内层的循环(在咱们的例子中为for循环)被破坏,执行从for循环结束后继续执行。

缘由:对于书中的break语句理解不够清晰,认为break就会直接跳出。

正确答案: A 个人答案: C
  • 错题3 Which of the following are true statements about check boxes? A. they may be checked or unchecked B. radio buttons are a special kind of check boxes C. they are Java components D. you can control whether or not they will be visible E. all of the above

解析:有关复选框的四个陈述中的每个都是真实的。

缘由:拿捏不许其余几个的准确性。

正确答案: E 个人答案: C
  • 错题4 In order to compare into, float and double variables, you can use <, >, ==, =, <=, >=, but to compare char and String variables, you must use compare to ( ), equals ( ) and equalsIgnoreCase ( ). A. true B. false

解析:您还可使用<,>,==,!=,<=,> =直接比较char变量,可是对于任何字符串比较,必须使用compareTo(),equals()和equalsIgnoreCase()。

缘由:在本周实验周我用实例发现这个问题,以前不是很明细。

正确答案: B 个人答案: A
  • 错题5 You might choose to use a switch statement instead of nested if-else statements if A. the variable being tested might equal one of several hundred int values B. the variable being tested might equal one of only a few int values C. there are two or more int variables being tested, each of which could be one of several hundred values D. there are two or more int variables being tested, each of which could be one of only a few values E. none of the above, you would never choose to use a switch statement in place of nested if-else statements under any circumstance

解析:switch语句只能在被测试的单个变量使用时使用,而且它是一个整型(int或Java中的char)。此外,由于您必须枚举每一个可能的测试值,因此switch语句只有在被测试值的数量很小时才有意义。

缘由:由于当时看书认为以为switch能够输入不少个对象,可是我忘记还须要枚举。

正确答案: B 个人答案: C
  • 错题6 If a switch statement is written that contains no break statements whatsoever, A. this is a syntax error and an appropriate error message will be generated B. each of the case clauses will be executed every time the switch statement is encountered C. this is equivalent to having the switch statement always take the default clause, if one is present D. this is not an error, but nothing within the switch statement ever will be executed E. none of the above

解析:虽然写这样一个转换语句是不寻常的,但它是彻底合法的。开关语句执行的正常规则适用于在计算开关表达式后执行的匹配的case子句。以后,依次执行全部后续子句,由于没有终止开关/大小写执行的中断语句。

缘由:这道题特别后悔作错了,由于其实交卷子回头看书的时候发现其实有关这道题的概念。

正确答案: E 个人答案: B
  • 错题7 How many times will the following loop iterate? Into x = 10; do { System.out.println(x); x--; } while (x > 0); A. 0 times B. 1 times C. 9 times D. 10 times E. 11 times

解析:变量x从10开始。每次经过循环,x递减,而且一旦x不大于0,循环最终退出,在这种状况下,这意味着一旦x变为0。所以,循环体执行x = 10, x = 9,x = 8等等,直到x = 0。这是11次。

缘由:计算问题.......

正确答案: E 个人答案: D
  • 错题8 Given that s is a String, what does the following loop do? For (into j = length ( ); j > 0; j--) System.out.print (s.charAt (j-1)); A. it prints s out backwards B. it prints s out forwards C. it prints s out backwards after skipping the last character D. it prints s out backwards but does not print the 0th character E. it yields a run-time error because there is no character at s.charAt (j-1) for j = 0

解析:变量j从字符串的长度向下计数到1,每次在位置j-1打印出字符。长度为1的字符是打印的第一个字符,这是字符串的最后一个字符。它会一直持续到j = 1,并在位置j-1或第0个字符处打印出字符,以便向后打印整个字符串。

缘由:个人理解和答案如出一辙,可是,问题是这个答案的意思不该该是向前打印出来么,后到前啊,让我很是的迷...

正确答案: A 个人答案: B
  • 错题9 Which of the following statements are true about Java loops? A. all three loop statements are functionally equivalent B. while loops and do loops are essentially the same; but while loops always execute at least once C. if you know the number of times that a loop is to be performed, the best loop statement to use is a while loop D. loops may be replaced by an appropriate combination of if-else and switch statements E. none of the above

解析:在Java中,与大多数语言同样,循环语句基本上都是相同的(而且几乎能够互换)。它们的主要区别与控制条件的评估时间以及是否存在增量/更新的语法有关。

缘由:发现for是知道次数应该首选的....

正确答案: A 个人答案: C
  • 错题10 The following loop is syntactically valid. for (into j = 0; j < 1000; j++) j--; A. true B. false

解析:Java编译器不关心你在循环中递增j,而是在循环体中递减j。从逻辑上讲,这个循环没有任何意义,由于j会不断递增和递减,因此它永远不会达到1000,但循环语法上没有任何问题。

缘由:当时认为是一个死循环

正确答案: A 个人答案: B
  • 错题11 In Java, it is possible to create an infinite loop out of while and do loops, but not for-loops. A. true B. false

解析:循环能够是无限循环,但Java for循环也能够是无限循环。在许多其余编程语言中,这种状况并不是如此,其中for循环具备设置的起点和终点,但Java for-loops比大多数其余语言的for-loops灵活得多。

正确答案: B 个人答案: A

缘由:没有理解清楚Java for-loops和for-loops的区别。

点评过的同窗博客和代码

  • 本周结对学习状况
  • 博客中值得学习的或问题:
    • 善于思考,勤于看书,能够在书中抠细节,把细节问题放大,解决起来更加方便。
    • 代码中值得学习的或问题:
    • 注释敲的很棒,可让别人清楚明白这里究竟是在作什么。
  • 基于评分标准,我给本博客打分:9分。得分状况以下:
  1. 正确使用Markdown语法(加1分):
  2. 模板中的要素齐全(加1分)
  3. 教材学习中的问题和解决过程, 一个问题加1分
  4. 代码调试中的问题和解决过程, 一个问题加1分
  5. 本周有效代码超过300行(加2分)
  6. 其余加分:
  • 代码Commit Message规范的加1分

  • 感想,体会不假大空的加1分

  • 本周结对学习状况

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

    • 内容详略得当;
    • 代码调试环节比较详细;
  • 基于评分标准,我给本博客打分:4分。得分状况以下:

  1. 正确使用Markdown语法(加1分):
  2. 模板中的要素齐全(加1分)
  3. 教材学习中的问题和解决过程, 一个问题加1分
  4. 代码调试中的问题和解决过程, 一个问题加1分

其余

  • 这一周感受上是很忙,其实至关于半周学一章知识,可是怎么讲,虽然累,并且还一堆事情,没有时间陪对象,也没有时间和父母打好长好长时间的电话,脾气也有点燥,早晚也要经历的,如今累点,说不定之后可能会好一点呢。其实每周都在看那个千帆图,不少人吐槽看不清本身的,只是以为,本身那根线比做函数,何时能求导不存在的时候,可能才让本身罢休。
  • 时间真的过的好快,飞快,光速同样,不少同窗都给我说,如今就像是读高三,比高三还苦,那大家应该来咱们中学,超级爽,总之,仍是那句话,<span style="color:red">本身选的路跪着也要走完它。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积)
目标 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
第六周 462/2658 1/7 15/130

参考资料

Java程序设计 蓝墨云 数字格式化