20172324《Java程序设计》第六周学习总结
教材学习内容总结
for(int ch=0;ch<line.length();ch++)
{
current = line.charAt(ch);//定义current是输入的字符串从索引0开始的字符
if(current>=‘A‘&¤t<=‘Z‘)//这里和Unicode有关,如果这个大写字母在A`Z之间
upper[current-‘A‘]++;//那么current-‘A‘就代表索引处那个特定的字符,索引处的值加1(最开始是0,因为没有出现过)
else
if(current>=‘a‘&¤t<=‘z‘)//同上嘛,就是小写的而已。
lower[current-‘a‘]++;
else
other++;
}
代码调试中的问题和解决过程
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++;
}
}
## 代码托管
(statistics.sh脚本的运行结果截图)

上周考试错题总结
- 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==
"控制流" 描述指令执行的顺序。它默认为线性 (或连续), 但通过使用诸如条件和循环等控制语句来改变。
- 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 相同。
- 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, 语句最大 = 总计/计数未执行, 再次避免潜在除法为零错误。
- 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。
- 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 和布尔值都是正确的, 但不能是双变量或浮点函数。
- 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 语句。
- 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 子句。随后, 所有后续子句都按顺序执行, 因为没有中断语句来终止交换机/案例执行。
- 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;==
看书看书看书看书看书看书
- 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循环一定会执行一次的,好好学数学,好好数。
- 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字符, 所以它打印整个字符串向后。
- 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点评我!)
- 正确使用Markdown语法(加1分)
- 模板中的要素齐全(加1分)
- 教材学习中的问题和解决过程, 加4分
- 代码调试中的问题和解决过程, 加4分
- 本周有效代码超过300分行,加2分
- 其他加分,加2分
- 排版精美的加一分
- 进度条中记录学习时间与改进情况的加1分
本周结对学习情况
其他(感悟、思考等,可选)
我学得要死不活的时候,王志伟说很简单。我感觉好悲伤,希望能够打他一顿解心头之狠。这个星期的感悟结束。
学习进度条
目标 |
5000行 |
30篇 |
400小时 |
|
第一周 |
200/200 |
2/2 |
20/20 |
|
第二周 |
329/500 |
2/4 |
18/38 |
|
第三周 |
619/1000 |
3/7 |
22/60 |
|
第四周 |
817/1734 |
4/7 |
38/60 |
|
第五周 |
674/2408 |
5/7 |
38/60 |
|
第刘周 |
1136/2870 |
6/7 |
50/60 |
|
参考资料
2017-2018-2学期 20172324《Java程序设计》第六周学习总结
原文:https://www.cnblogs.com/amberR/p/8849517.html