20172330 2017-2018-1 "Java Programming" Fifth Week study summary

Source: Internet
Author: User

20172330 2017-2018-1 "Java program design" Fifth week study summary textbook study content summary fifth chapter
  • The first is the understanding of the various operators: just beginning to think that equality is =, there are some other symbols are quite simple, and then in the further learning to know the "= =" and "! = "are all equal operators, and"! "," && "," | | " Represent non, with, or.

    Problems in teaching materials learning and the solving process
  • The next is the IF statement:
    A 1.if statement consists of a reserved word if, a Boolean expression immediately followed by, and a statement or set of statements. The conditional expression is enclosed in parentheses, and the result of the operation can only be ture or false. For Ture, execute the statement in the IF statement, then execute the IF statement, or false to not execute the statement in the IF statement, and then continue executing the statement in the IF statement.
    The 2.if-else statement enables a program to execute a piece of code when the value of a conditional expression is true, and to execute another piece of code when the value is false.
    3. Using statement blocks: In Java, you can replace any statement with a block of statements. A statement block is a collection of multiple statements enclosed in parentheses.
    Nesting of 4.if statements: A. Embed another if statement in one if statement, which is called nesting of the IF statement. B. In a nested if statement, the ELSE clause matches the last and unmatched if statement in front of it.
  • There is also a while statement:
    A 1.while statement is a looping statement that evaluates the value of a Boolean expression like an if statement and executes a statement (called a loop body) when its value is true. But the while statement evaluates the value of the expression again after the loop body finishes executing, which differs from the IF statement. If the expression evaluates to ture at this point, the loop body is executed again. The loop body does not go down until the expression is false. |while executes the same statement until its condition becomes false. |
    2. Infinite loop: The program must be carefully designed to avoid infinite loops.
    3. Nested loops: A loop body may contain another loop, which is called a nested loop. Each time the outer loop is executed, the inner loop executes a specified number of completion loops.

    Sixth chapter
  • The first is the switch statement
    Another conditional statement in 1.Java is a switch statement that allows a program to select one of several execution paths to execute, and the selection of these paths is based on a single value. Using multiple If statements can construct the same logic, but using a switch statement makes the code easier to understand.
    The 2.switch statement evaluates the value of an expression first, and then matches the value with several possible case clauses. Each of these values has an execution statement associated with it. When the value of an expression is computed, the control is transferred to the first case clause that matches the value of the expression.
  • The second is the DO statement
    The 1.do statement is similar to the while statement, and the Do loop repeats the statements in the loop body until the loop control condition becomes false
  • The third is the For statement
    1.for statements are typically used in cases where the number of loops is known.
    The control header of the 2.for loop contains three parts separated by semicolons. Before the loop begins, the first part of the initialization is executed, and the second part is a Boolean expression that evaluates (like a while loop) before executing the loop body. If the calculated value is ture, the loop body is executed and then the third part, called the increment, is executed.

Problems in teaching materials learning and solving problems
    • Issue 1: Understanding of iterators
    • Problem 1 Solution: After reviewing the data, it is understood that iterators provide a way to access individual elements in a container object without exposing the internal details of the object container.
      (https://www.cnblogs.com/zyuze/p/7726582.html)

    • Use of the problem 2:for statement
    • Problem 2 Solution: After doing the example 64, the book says that the for statement is especially useful for situations where the loop is clearly known before the loop executes. The For loop is more convenient for separating the code that sets and controls the number of loops in the loop header from the loop body, which is easier to do.

Problems in code learning and the process of solving them
    • Issue 1: The first is because the previous encoding did not take into account the stop of the while loop, resulting in unlimited operation when doing pp51.
    • Problem 1 Solution: When checking the code, it is found that the contents of the statement block are not clearly emphasized during the while loop, and then run successfully after the change.

    • Question 2: When doing pp53, the program does not have a problem, but the output is wrong.
    • Problem 2 Solution: After consulting the Shing classmate found that I at the beginning of the definition when the left set to 0, resulting in no matter how the output will contain a 0, and then the second time found that the last read is always a final number, finally after the modification of the successful solution, in this is also very grateful to Shing classmates help.

Code Hosting


Last week's summary of the wrong quiz
  • Which of the sets of statements below would add 1 to x if x are positive and subtract 1 from X if x are negative but l Eave 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--;
    If x is a positive number, X + + is performed with a negative x, otherwise, nothing happens, or x is not affected. In a, C, D, and E, the logic is incorrect. In a, X is done if x is not positive, so if X is 0, X becomes-1, which is the wrong answer. In C, if X is a positive number, it performs x + +. In either case, the next statement is executed and if X is not a negative number, the ELSE clause is executed, and X is set to 0. Therefore, if X is a positive number, it becomes 0 after this set of code. In D, X + + and X are performed if x is not 0. In E, this code does not attempt to determine whether X is a positive or negative number, it adds only one, and then subtracts 1 from X, making the x the same.

  • Assume, Count is 0, and Max is 1. The following statement would do which of the following? if (count! = 0 && total/count > max) max = Total/count;
    A. The condition short circuits and the assignment statement are not executed
    B. The condition short circuits and the assignment statement are executed without problem
    C. The condition does not short circuit causing a division by zero error
    D. The condition short circuits so, there are no division by zero error when evaluating the condition, but the assignment Statement causes a division by zero error
    E. The condition would not compile because it uses improper syntax
    because the count is 0, (count! = 0) is false. Because the left-hand side of the condition is false, the condition is short-circuited, so the right hand side is not counted. Therefore, a potential division error is avoided. Because the condition is false, the statement max = total/count is not executed, again avoiding potential division to zero error.

  • Which of the following is true statements about check boxes?
    A. They may checked or unchecked
    B. Radio buttons is a special kind of check boxes
    C. They is Java components
    D. Can control whether or not they would be visible
    E. All of the above
    Each of the four statements about a check box is true.

  • Each case in a switch statement must terminate with a break statement.
    A. True
    B. False
    If the interrupt statement does not exist, the control flow continues into the next case.

  • A switch statement must has a default clause.
    A. True
    B. False
    The default clause is optional.

-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; The
Java conditional operator tests a condition in this case (x 0), and if true, returns "? "After the value. (In this case, X), if False, the following value is returned: (in this case, 0). The original if statement specifies y as x (if x 0), otherwise 0. This is done by specifying y as x or 0 based (x 0), as shown in. In B, X is specified as the value of the backward Y or 0. In C, the conditional operator is syntactically invalid. In D, Y is set to True or false, depending on (x 0), and the statement in E is syntactically invalid.

    • Which of the following is true statements about check boxes?
      A. They may checked or unchecked
      B. Radio buttons is a special kind of check boxes
      C. They is Java components
      D. You can control whether or not they'll be visible
      E. All of the above
      After flipping through the textbooks, I found that all aspects were correct.

    • In Java, it's possible to create a infinite loop out of the while and does loops, but not for-loops.
      A. True
      B. False
      While and do loops can be infinite loops, but for loops can be infinite loops. This is not true in many other programming languages, because For-loops has a starting and ending point for a set, but Java For-loops is much more flexible than most other languages for-loops.

Other (sentiment, thinking, etc., optional)

Continue to work hard to tap the code.

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
target 5000 Line 30 400 hours
first week 180/180 2/2 20/25
second week 312/414 2/4 20/45
third week 557/971 2 /6 25/70
fourth week 1217/2242 2/8 44/114
fifth week 734/2976 2/10 24/13 8
    • Planned study time: 24 hours

    • Actual learning time: 24 hours

Resources

[Java Programming and Data Structure Tutorial (second edition)]

[Java Programming and Data Structure Tutorial (second Edition) "Learning Guide]

20172330 2017-2018-1 "Java Programming" Fifth Week study summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.