2017-2018-2学期 20172324《Java程序设计》第六周学习总结

20172324《Java程序设计》第六周学习总结

教材学习内容总结

  • 如何创建数组以及int[] X与int X[]的区别(编译时是没有差别的,只是前者与其他类型的声明方式有一致性)
  • 每一个java数组都是一个迭代器。
  • 数组是作为参数传递给一个方法的,实际上传递的是原始数组引用的副本。
  • 对象数组(基本数据类型+对象)
  • 二维数组中前一个索引值代表行,另一个索引值代表列。
  • 可变长度参数用...

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

  • 问题1: Family代码中String...name中的...是什么意思。
  • 问题1解决方案:这是jdk1.5的新特性:变长变量。也就是说可以传入任意多个参数。比用数据更灵活一些,不会出现一些数组越界等的异常。 如:

- 问题2:pp8.3我有点不懂。就是upper[current-'A']++那里,到底是什么加了1? 
- 问题2解决方案: 我只能一步步写注释。

for(int ch=0;ch<line.length();ch++)
{
current = line.charAt(ch);//定义current是输入的字符串从索引0开始的字符

        if(current>='A'&&current<='Z')//这里和Unicode有关,如果这个大写字母在A`Z之间
            upper[current-'A']++;//那么current-'A'就代表索引处那个特定的字符,索引处的值加1(最开始是0,因为没有出现过)

        else

            if(current>='a'&&current<='z')//同上嘛,就是小写的而已。
                lower[current-'a']++;
            else
                other++;
    }
    


## 代码调试中的问题和解决过程
- 问题1:pp8.1中,我开始是想定义一个数组,把我想输入的值按大小放进索引里,没有出现的值就用0补齐,并且如果出现相同的值,那个索引值里数字的个数就增加1,后来发现,一个索引里只能放一个值,不存在相同数字放在同一个索引下的情况。导致我不管输入什么值输出的个数全都是0。
- 问题1解决方案:==利用二维数组==。第一步先创建两个都包含0~50这51个数的数组,一个用来放你输入的数,一个用来计算前一个数组中不同索引里相同数的值的个数。第二部用Scanner方法输入你想输入的数,将它们一个个放在数组A里。第三步,计算你输入的数值个数,并且定义一个初始值为0,又在输入数值个数范围内的数,相同的值就在数组B中对应位置增加出现次数。第四步输出从0到50这51个数且你输入的数出现的频率。
- 问题2: pp8.5,如何表示继续输入一个数。
- 问题2解决方案:在书上第五章提到过,String一个字符串,然后定义为y,利用字符串是否相等,即equalsIgnoreCase()这个比较,决定是否继续输入。
- 问题3:继续上一个问题...如图所示我不停在“是否继续输入”这个问题上循环,还到不了输入数据这。![](https://images2018.cnblogs.com/blog/1332976/201804/1332976-20180415205553484-1145105126.png)![](https://images2018.cnblogs.com/blog/1332976/201804/1332976-20180415205603362-387991277.png)




- 问题3解决方案:编写的时候直接向第五章一样的String了一个str,还String了一个定义为“y”的another值,但其实在这章里不需要str来输入回文。所以定义一个another就可以了,否则的话就会像我这样了....其实我还是不太懂,我再去看看书。

String another = "y";//创建一个字符串命令它表示为y
int[] list = new int[50];//可以放50个数的数组
//创建一个可以连续输入数字的循环
while(another.equalsIgnoreCase("y"))//哦~这里的another要和下面输入的another做比较
{
Scanner scan = new Scanner(System.in);
System.out.print("是否继续输入(y/n): ");
another = scan.nextLine();//就是这里的

        if (another.equalsIgnoreCase("y") )//another输入为y就可以输入数据,所以不需要多的字符串。
        {
            System.out.print("Enter your number: ");
            number = scan.nextInt();

            list[i] = number;
            i++;
        }
    }

```

  • 问题4:pp8.6是一个很大的问题,无解...

    代码托管

(statistics.sh脚本的运行结果截图)
1332976-20180415211455634-153799549.png

上周考试错题总结

  1. The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as
    A . boolean execution
    B . conditional statements
    C . try and catch
    D . sequentiality
    E . flow of control
    "控制流" 描述指令执行的顺序。它默认为线性 (或连续), 但通过使用诸如条件和循环等控制语句来改变。

  2. 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--;
    如果 x 为正数, 则在 x 为负 x 的情况下执行 x++, 否则, 不会发生任何情况, 或者 x 不受影响。在 A、C、D 和 E 中, 逻辑不正确。在 A, x-是做如果 x 是不积极的, 因此, 如果 x 是 0, x 成为-1, 这是错误的答案。在 C 中, 如果 x 为正数, 则执行 x++。在任一情况下, 将执行下一语句, 如果 x 不是负值, 则执行 else 子句将 x 设置为0。因此, 如果 x 是正数, 则在这组代码之后变为0。如果 x 不是 0, 则在 D、x++ 和 x 中都执行。在 E 中, 此代码不尝试确定 x 是正数还是负数, 它只添加一个, 然后从 x 中减去 1, 使 x 相同。

  3. 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
    因为计数是 0, (计数! = 0) 是假的。因为 & & 条件的左手边是假的, 所以条件是短路的, 所以右手边是不计算的。因此, 避免了潜在的除法错误。由于条件为 false, 语句最大 = 总计/计数未执行, 再次避免潜在除法为零错误。

  4. 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
    有关复选框的四个语句中的每一个都是 true。

  5. When comparing any primitive type of variable, == should always be used to test to see if two values are equal.
    A . true
    B . false
    这对 int、短、字节、长、char 和布尔值都是正确的, 但不能是双变量或浮点函数。

  6. 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
    只有在测试单个变量并且它是整数类型 (在 Java 中为 int 或 char) 时, 才可以使用 switch 语句。

  7. 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 子句。随后, 所有后续子句都按顺序执行, 因为没有中断语句来终止交换机/案例执行。

  8. The statement if (x < 0) y = x; else y = 0; can be rewritten using a conditional operator as
    A . y = (x < 0) ? x : 0;
    B . x = (x < 0) ? y : 0;
    C . (x < 0) ? y = x : y = 0;
    D . y = (x < 0);
    E . y = if (x < 0) x : 0;
    看书看书看书看书看书看书

  9. How many times will the following loop iterate?
    int 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
    没话说….do循环一定会执行一次的,好好学数学,好好数。

  10. Given that s is a String, what does the following loop do?
    for (int j = s.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字符, 所以它打印整个字符串向后。

  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
    诚然, 虽然while和do循环可以是无限循环, 但for 循环可以是无限循环。在许多其他编程语言中, 这不是真的, for 循环有一个设置的开始和结束点, 但是 Java for 循环比大多数其他语言的 for 循环要灵活得多

    结对及互评

点评模板(why点评我!)

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

    • 界面排版很好看
    • 问题分析很详细,有自己的思考
    • 对学习的总结很到位,提出和解决的问题也是很重点的知识点
  • 代码中值得学习的或问题

    • 关键代码注释很详细
  • 基于评分标准,我给本博客打分:14 。得分情况如下:
  1. 正确使用Markdown语法(加1分)
  2. 模板中的要素齐全(加1分)
  3. 教材学习中的问题和解决过程, 加4分
  4. 代码调试中的问题和解决过程, 加4分
  5. 本周有效代码超过300分行,加2分
  6. 其他加分,加2分
  • 排版精美的加一分
  • 进度条中记录学习时间与改进情况的加1分

本周结对学习情况

  • 结对同学学号21号
  • 结对学习内容

    • 一起讨论学习了课后编程项目pp8.1和pp8.5,pp8.6我是真的不行了,希望你学会了来救救我。

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

我学得要死不活的时候,王志伟说很简单。我感觉好悲伤,希望能够打他一顿解心头之狠。这个星期的感悟结束。

学习进度条

代码行数(新增积)博客量(新增积)学习时间(新增积)重要成长
目标5000行30篇400小时
第一周200/2002/220/20
第二周329/5002/418/38
第三周619/10003/722/60
第四周817/17344/738/60
第五周674/24085/738/60
第刘周1136/28706/750/60

参考资料

转载于:https://www.cnblogs.com/amberR/p/8849517.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值