Java Basic Course Learning notes (3)

Source: Internet
Author: User

Knowledge Essentials: operator (Master) keyboard entry (mastering) Flow control statement if statement (master)
1: operator (master) (1) Arithmetic operatorsa:+,-, *,/,%,++,--b:+ usage A: addition B: Positive sign C: string connector c:/and% of the difference data when doing division operation,/get is quotient, percent gain is remainder d:++ and--usage a: their function is self-increment or self-subtraction B: Use     * * Use alone before and after the operation data.    The a++ or ++a effect is the same.      * * Participation in the operation is placed before the operand: self-increment or decrement, then participate in operation int a = 10;     int b = ++a;      Put in the back of the operand: first participate in the operation, and then self-increment or decrement int a = 10; int b = a++; (2) Assignment operatora:=,+=,-=,*=,/=,%=, such as b:=, is called the assignment operator and is the most basic assignment operator, int x = 10; Assign 10 to the variable x of type int.C: Features of the extended assignment operatorimplicit automatic casts. Interview question: #面试 #Short S = 1;    s = s + 1;    Compile error, possible loss of precision short s = 1;        s + = 1;    Correctly, the extended assignment operator implies an automatic cast. s + = 1;                 Unequal to S = s + 1; It is equal to S = (data type of s) s + 1 is there a problem with the above code? (3) comparison operatorsA:==,!=,>,>=,<,<= B: Regardless of whether the operator is simple or complex, the end result is a Boolean type. C: Don't write = = (4) Logical operatorsa:&,|,^,!, &&,| | B: The logical operator is used to concatenate a Boolean type of formula C: Conclusion&: false if false|: True is true^: The same is false, and the difference is true. couple relationship. !: Not true false, not false true&&: The result is the same as the &, except that it has a short-circuit effect. The left side is false, and the right side is not executed. | |: Results and | are the same, except for short-circuit effects. The left is true and the right side is not executed. (5) Bitwise operator (learn)  Special usage of a:^ one data for another data bit XOR or two times, the number is unchanged B: Question #面试 #A: Please implement the exchange of two variables * * Use a third-party variable * * with bitwise XOR operator left A,b,a to the right a^b B: Use the most efficient way to calculate the result of 2 times 8 2<<3

The details of the bitwise operator

<<

Empty fill 0, removed high-level discarded.

>>

The shifted binary, the highest bit is 0, after the right shift, the vacancy is 0, the highest bit is 1, the highest bit is 1.

>>>

The top bit of the shifted binary is either 0 or 1, and the vacant bit is filled with 0.

&

Any bits and 0 perform the & operation, the result is 0, and 1 for the & operation result is the original value.

|

Any bits and 0 carried out | operation, the result is the original value; and 1 for | The result of the operation is 1.

^

any of the same bits ^ operations, the result is 0; not the same bits ^ operation result is 1.

(6) ternary operatorA: Format comparison expressions? Expression 1: Expression 2;   B: Execution Flow: Evaluates the value of the comparison expression first to see if it is true or false.   If true, the expression 1 is the result.  If False, the expression 2 is the result. C: Case: (slightly) A: compare two data for Equality B: Get the maximum value in two data c: Get the maximum value in three data 2: Keyboard entry (Master)(1) in the actual development, the data is changed, in order to improve the flexibility of the program, we add keyboard input data.   (2) How to achieve it? Now remember A: Guide package import Java.util.Scanner;  Location: On top of Class B: Create Object Scanner sc = new Scanner (system.in); C: Get data int x = Sc.nextint (); (3) Adding the case of ternary operator to keyboard input improvement. 3: Process Control statement(1) sequential structure from top to bottom, followed by (2) Select structure according to different choices, execute different code (3) loop structure do some duplicate code 4:if Statement (master) (1) three formatsA: Format 1 if (comparison expression) {statement body;   Execution process: Judge the value of the comparison expression, whether true or False if true, executes the statement body if it is false, does not execute the statement body B: Format 2 if (comparison expression) {statement body 1;   }else {statement body 2;   Execution process: Judge the value of the comparison expression, whether true or False if true, executes the statement body 1 if false, executes the statement body 2 C: Format 3 if (comparison expression 1) {statement Body 1;   }else if (comparison expression 2) {statement body 2;   } ... else {statement body n+1;    The execution process: Determine the value of the comparison expression 1, whether true or False if true, executes the statement body 1 if false, continue to judge the value of the comparison expression 2, to see whether true or False if true, executes the statement body 2    If false, continue to judge the value of the comparison expression 3 to see if it is true or false ... If all is not satisfied, execute the statement body n+1 (2) precautionsA: Comparing expressions whether simple or complex, the result is that the Boolean type B:IF statement control statement Body if it is a statement, you can omit the curly braces, if it is more than one, cannot be omitted.  Suggestion: Never omit.  C: Generally, there are left curly braces, there is no semicolon, there is a semicolon, there is no left curly brace.  D:else If there is no if, the comparison expression is not present. E: Three If statements are actually a statement, as long as there is one execution, the other is no longer executed. (3) Case:A: Compare whether two numbers are equal B: Gets the maximum value in two numbers C: Gets the maximum value in three numbers (nesting of If statements) D: According to the score output corresponding to the class E: According to the month, the output corresponding to the season F: According to the x to calculate the corresponding Y value and output (4) The relationship between ternary operator and the second form of if statementAll ternary operators can be implemented, and the second form of the IF statement can be implemented.  Conversely, it is not established.  If the statement body that is controlled by the second format of the IF statement is an output statement, it is not possible. Because the ternary operator is an operator, you must have a result returned and cannot be an output statement.

Java Basic Course Learning notes (3)

Related Article

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.