Java Learning notes (2)

Source: Internet
Author: User

Java Basics:

1: operator (1) arithmetic operator a:+,-, *,/,%,++,--b:+ 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 to put the same effect on the front and back of the operation data. The a++ or ++a effect is the same. * * Participate in the operation is placed in front of the operand: first increment or decrement, then participate in operation int a = 10;int B = ++a; Put in the back of the operand: participate in the operation first, then increment or decrement int a = 10;int B = a++;(2) assignment operator a:=,+=,-=,*=,/=, %=, 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: The characteristic of an extended assignment operator implies an automatic cast. Interview question: short s = 1;s = s + 1;short s = 1;s + = 1; Is there any problem with the above code? (3) comparison operator A:==,!=,>,>=,<,<=b: The end result is a Boolean type regardless of whether the operator is simple or complex at both ends. C: Don't write = = (4) logical operator a:&,|,^,!, &&,| | B: The logical operator is used to concatenate Boolean type C: Conclusion &: False if false|: True then true^: Same false, different true. Couple relationship.!: Not true then false, not false true&&: The result is the same as &, 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 (understanding) special usage of a:^ one data for another data bit XOR or two times, the number is constant B: Face question A: Please implement the exchange of two variables * * Using a third-party variable * * With the left a,b,a of the bitwise XOR operator to the right A^BB: Calculate the result of 2 times 8 in the most efficient way 2 <<3 (6) ternary operator A: Format comparison expression? 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: 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 (1) in the actual development, the data is changed, in order to improve the flexibility of the program, we addInput data into the keyboard. (2) How to achieve it? Now remember a: Guide package import Java.util.Scanner; position: On Top of Class B: Create object Scanner sc = new Scanner (system.in); C: Get data int x = Sc.nextint ();(3) Add the case of ternary operator to keyboard entry improvement. 3: Flow control statement (1) sequence structure from top to bottom, execute (2) Select structure according to different selection, execute different code (3) loop structure do some duplicate code 4:if statement (1) Three format a: format 1if (comparison expression) {statement body;} Execution flow: Determine 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 2if (comparison expression) {statement body 1;} else {statement body 2;} Execution flow: Determine 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 3if (comparison expression 1) {statement body 1;} else if (comparison expression 2) {statement body 2;} ... else {statement body n+1;} 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 it is 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) Note A: Comparison expression whether simple or complex, the result is a 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, you cannot omit. 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 two numbers for Equality B: Get the maximum value in two numbers C: Get the maximum of 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) Ternary operators and if statements the second format of the relationship all ternary operators can be implemented, if the second form of the 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, not an output languageSentence 

  

Java Learning notes (2)

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.