The second three weeks summary

20,182,305 2019-2020-1 "data structures and object-oriented programming," the second three weeks learning summary

Learning content summary

Learning materials two weeks learning the main data types and expressions, classes and objects of the Java language. Including how to set a variable, input data, using the + concatenation string, variable assignment, calculation operation, forced to change the data type. Rondom class by using the random number generated, formatted output. And the integrated use of these simple programming such as calculators, random program.

Textbook learning and problem-solving process

  • Question 1: The difference between the print and println;
  • Problems Solution 1: println automatically wrap the outputs, roughly equivalent to the effect of print + \ n, but may be used after the print \ t, \ r outputs different formats. The integrated use of more flexible and more powerful.
  • Question 2: distinguish the difference between char and string types in use;
  • Problem 2 Solution: char for the character, and the string to string. Finally there is the biggest difference is that the "\ 0" at the end of the string. Therefore, when using char = string.charAt (int) method, if mistakenly labeled char string will be given because it is not compatible with the type.
  • Problem 3: not understand the relationship between classes and methods;
  • Question 3 Solution: query data and reading textbooks, I gradually came to understand the relationship between class and contains the methods, but also understand the way to call class method (for example: Math.PI, Die.roll);

Code debugging and problem solving in the process

  • Question 1: The question of when to do the book appeared on the division output with missing fractional part.
  • Problem 1 Solution: After checking found I aver = (float) (a + b + c) / 3; written in the wrong aver = (float) ((a + b + c) / 3); cause output decimals are all 0 instead of the correct result.
  • Question 2: An error occurred while using the Scanner class input data, suggesting InputMismatchException.
  • Problems Solution 2: The method and the original does not match the input type, the input sentence modified corresponding to the type of variable.
  • Question 3: The title PP3.1, do compile error occurs in the book:
  • Problem 3 Solution :: char type variable b is a character is, the type is a string of a string. The difference is that last "0 \" at the end of the string, and no character, it returns only when a character does not meet charAt string to define the "\ 0" at the end, and thus would be wrong.

Code hosting

Last week exam wrong question summary

  • A wrong question: The word println is a (n) (println is a word)

A. Method (Method)

B. Reserved word (reserved word)

C. Variable (variable)

D. Class (class)

E. String (String)

  • The reason: println System.out is a method, not a reserved word. So this title selected A instead E.
  • Two wrong question: What is output with the statement System.out.println (x + y); if x and y are int values ​​where x = 10 and y = 5 (if x and y is a number of type int, x =? 10, y = 5, the statement System.out.println (x + y); what output is)?

A . 15

B . 105

C . 10 5

D . x+y

E. An error since neither x nor y is a String (an error due to the x and y strings are not caused)

  • Println reason only when double quotes brackets including strings, i.e. using only the + output string data type string is automatically converted from a digital output. Now there is no character string in brackets, directly outputs the calculation result of x + y = 15.
  • Wrong title three:
    the If you want to INTO at The Store at The String value name "George Bush", Would you do Which of Statement (if you want to "George Bush" this value is stored as a string type name, you will perform the piece? statement?)

A . String name = "George Bush";

B . String name = new String("George Bush");

C . String name = "George" + " " + "Bush";

D . String name = new String("George" + " " + "Bush");

E. Any of the above would work (described above can be done)

  • The reason, after careful reading reveals that the final results of these methods defined in fact the same. Only a slight difference on all models operate.
  • Wrong question four: the What z value by Will have have the Execute at The IF WE following the Assignment of Statement?
    Int z = 50 / 10.00; (if we execute the following assignment statement, z will get what value?)

A . 5

B . 5.0

C . 50

D . 10

E. None of the above, a run-time error arises because z is an int and 50 / 10.00 is not (all of the above error, because z is an integer and 50 / 10.00 is not, runtime error is generated)

  • Cause: Results 50 / 10.00 as a decimal data type and the z-shaped, can not save a decimal.
  • Wrong question five: In order to create a constant, you would use which of the following Java reserved words (to create a constant, which of the following would you use Java reserved word?)?

A . private

B . static

100. int

D . final

E . class

  • The reason: the variables used to create the final can not be changed in the course of the entire program is running, the program is more conducive to stable operation.
  • Wrong question six: Java is a strongly typed language What is meant by "strongly typed" (Java is a strongly typed language "strongly typed" refers to what is.?).?

A. Every variable must have an associated type before you can use (type before using variables, each must have associated with it) it

B. Variables can be used without declaring their type (variables can be used without its declared type)

C. Every variable has a single type associated with it throughout its existence type in the program, and the variable can only store values ​​of that type (in the program, each variable has an associated, and the variable can store the value of this type)

D. Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to allow to change the type (variable exists in the program be, as long as it is currently stored value is the current type declaration)

E. Variables are allowed to change types during their existence in the program but only if the change is to a narrower type (variable exists in the program is allowed to change the type, but only narrowed conversion)

  • Seven wrong question: A variable of type boolean will store either a 0 or a 1. (Boolean type variable will be stored as 0 or 1)

A . true

B . false

  • Reason: In Java, Boolean variable has only two values: true, false, instead of 0,1.
  • 错题八: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--;

  • The reason: because of language issues, failed to accurately understanding the problem.
  • 错题九:In order to compare int, float and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo( ), equals( ) and equalsIgnoreCase( ).

A . true

B . false

  • Reason: comparison may be used for character>, <, etc. == symbols, but can only be used for string comparison compare () method such.

Guess you like

Origin www.cnblogs.com/Java-cn/p/11567325.html