zoukankan      html  css  js  c++  java
  • 20172329 2017-2018-2《程序设计与数据结构》第六周学习总结

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

    教材学习内容总结

    第八章:数组

    一、数组元素
    1、访问数组的方式:“数组名[索引值];不能混淆索引值和存于该索引值位置的数据值。

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

    三、对象数组
    1、一个数组可以有多个对象,每个对象又由一组变量和使用这些变量的方法组成,而对象中的变量可能本身又是数组;

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

    • 问题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++;
            }
    

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

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

    • 问题2:有一句代码经常看见,但是不是很理解:

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

    • 问题3:在学习8.4命令行形参那个例题后,感觉上是发现了新世界,因为一开始我们就学习了他们的各部分(String[] args:从控制台接收参数).但是就是我们一直死记忆的main方法的那一句

          public static void main(String[] args)
    

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

    • 问题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分

    其他

    • 这一周感觉上是很忙,其实相当于半周学一章知识,但是怎么讲,虽然累,而且还一堆事情,没有时间陪对象,也没有时间和父母打好长好长时间的电话,脾气也有点燥,迟早也要经历的,现在累点,说不定以后可能会好一点呢。其实每周都在看那个千帆图,很多人吐槽看不清自己的,只是觉得,自己那根线比作函数,什么时候能求导不存在的时候,可能才让自己罢休。
    • 时间真的过的好快,飞快,光速一样,很多同学都给我说,现在就像是读高三,比高三还苦,那你们应该来我们中学,超级爽,总之,还是那句话,自己选的路跪着也要走完它。

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积)
    目标 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程序设计
    蓝墨云
    数字格式化

  • 相关阅读:
    简单明了的带你理解springboot原理和三大核心注解
    Spring Boot(一):入门篇
    【Mysql优化】聚簇索引与非聚簇索引概念
    Mysql索引原理与优化
    Mysql全文索引的使用
    索引的优缺点,如何创建索引
    184 01 Android 零基础入门 03 Java常用工具类03 Java字符串 02 String类 04 例:字符串与byte(即:字节)数组间的相互转换
    183 01 Android 零基础入门 03 Java常用工具类03 Java字符串 02 String类 03 String常用方法(下)
    182 01 Android 零基础入门 03 Java常用工具类03 Java字符串 02 String类 02 String常用方法(上)
    181 01 Android 零基础入门 03 Java常用工具类03 Java字符串 02 String类 01 String常用方法简介
  • 原文地址:https://www.cnblogs.com/qh45wangwenbin/p/8847516.html
Copyright © 2011-2022 走看看