Java review (2) (calculation, escape sequence, evaluation rule, type conversion, instruction execution statement)

Part 1 "Calculation"

  1. Formula construction (1) Number = operand (operand. The target of the operator) ② Operator It consists of only these two.
  2. Literal Among the operands, a specific value such as 5 or book is called a literal. Part 2 "Escape sequence" Special characters can be output to the screen by using . ①¥ ‘ ②¥ “ ③¥¥ You can also start a new line by putting it in the text. ¥n

Part 3 "Rules for evaluation"

  1. The calculation method is very ordinary If 1 + 2 --6 The answer is -3
  2. Evaluation order 5 + 2 * 2 = 9 ( 5 + 2 ) * 2 = 14 If A = B = 1, then ①A = B = 1 ②A = 1 ③1 As a result, A becomes 1. Therefore, the following formula becomes as follows. ①A = 2 * 1 = 2 + 3 * 2 ②A = 2 * 1 = 8 ③A = 10 ④10
  3. Strength of operator evaluation (simplified version) high Low (++ - -) > ( * / % ) > ( + - ) > ( = += -+ /= %=) The assignment is done last, so it has the lowest priority.
  1. Notes on the increment operator Do not use it with other operators as it will cause bugs.

Part 4 "About type conversion"

  1. Type rules For example, the String type is not included in the int type. However, type conversion may be done automatically under certain rules.
  2. Conversion by substitution If it's a number, it has a size For example, an int smaller than long goes into long Floats smaller than double can be assigned to double.
  1. Notes on assignment type conversion Float and double that handle decimal points cannot be assigned to int and long that handle integers.
  2. Forced conversion by cast int num = 3.2; Such assignment is not possible, but it can be compiled by writing as follows. int num = ( int ) 3.2; When executed, 3 is assigned to num.
  3. Operation type conversion 5 / 2 = 2 5.0 / 2.0 = 2.5 The above is the calculation between ints and doubles. 5.0 / 2 = 2.5 In the above, int type 2 is converted to double type 2.0. Then it becomes 5.0 / 2.0 and the result is 2.5.
  4. String type conversion System.out.println (“Tomorrow is” + 5 + “Sun”;); In the above case, 5 is converted to String type.

Part 5 "Instruction execution statement" It is provided by Java or you can create it yourself (calling a method). For example, there are the following. System.out.print(); The parentheses contain what are called arguments and parameters. (Parameter: A value input from the outside that affects the behavior of software and systems. The following is a list of typical ones. Math.max (A, B); Substitute the larger value Integer.parseInt (); Converts a parameter to an int type. new java.util.Scanner (System.in) .nextLine (); Accepts keyboard input

Recommended Posts

Java review (2) (calculation, escape sequence, evaluation rule, type conversion, instruction execution statement)
Java study # 3 (type conversion and instruction execution)
Java instruction execution statement
[Java] Calculation mechanism, operators and type conversion
[Java] Escape sequence
What I learned in Java (Part 3) Instruction execution statement
[Java] Date type conversion
[Java] List type / Array type conversion
[Java] Precautions for type conversion
[Java] Type conversion speed comparison
Java Primer Series (Type Conversion)