Java Fundamentals (iii)

Source: Internet
Author: User
Tags bitwise

Here are some of the lessons I summarized in the previous lesson and the code is most of the teacher's notes personally think is very good, but also a more classic content, sincere hope that these for those who want to learn some help!

Because the code is sub-module upload is very inconvenient. Also more, speak of is more clear! If you need to be able to leave your email in the comments I see will be sent to you for free! Thank you for this platform let us all progress together!! Remember that the programmer is selfless!!!

Also very welcome to my blog to watch the blog address: http://www.cnblogs.com/duscl/

1: operator (mastering) (1) arithmetic operator a:+,-, *,/,%,++ A: addition B: Positive sign C: string connector c:/and% difference data when doing division operation,/get is quotient, percent gain is remainder d:++ and      Usage A: Their role is self-increasing or self-reducing B: use * * use alone in front of the operating data and behind the effect.     The a++ or ++a effect is the same. * * Participation in operation is preceded by the operand: self-increment or decrement, then

Participate in operation int a = 10;      int b = ++a; At the back of the operand: first to participate in the operation, and then to increase self-

or self-decrement       int a = 10;       int B = a++;   (2) The 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: Features of the extended assignment operator     implicit automatic casts.         Interview title:     short s = 1;     s = s + 1;          short s = 1;     s + = 1;      What's wrong 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:&,|,^,!, &&,| | &NBSP;&NBSP;B: The logical operator is used to concatenate a Boolean   c: Conclusion    &: False if False    |: True    ^: The same is false, the difference is true.      relationships with couples.    !: False if not true, False true        &&: Result and & It's the same, it's just a short-circuit effect. Left is false, right

Side does not execute. | |: The result and | are the same, but with short-circuit effect. Left is true, right

Side does not execute. (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 bitwise XOR operator left A,b,a right a^   b b: Please 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 (Mastery) (1) In actual development, the data is changing, 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: Flow control Statement (1) sequential structure from top to bottom, Execution (2) Select structure according to different selection, execute different code (3) loop structure do some duplicate code

4:if Statement (Master)   (1) Three formats   a: Format 1    if (comparison expression) {     statement body;     }         Execution process:      Determine the value of the comparison expression to see if it is true or false       If true, executes the statement body      if False, does not execute the statement body      b: Format 2     if (comparison expression) {     statement body 1;    }else {     statement body 2;     }         Execution process:      Determine the value of the comparison expression to see if it is true or false       If true, executes statement body 1      If false, executes 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;     }         execution process:      Judging the value of the comparison expression 1, seeTrue or False      if true, executes the statement body 1      If false, continues to judge the value of the comparison expression 2, to see if it is

True or False if true, executes the statement body 2 if false, continuing 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;

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 two numbers for equality B: Get the maximum value in two numbers C: Get 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) Ternary operator   F statement the second format of the relationship all ternary operators can be implemented, the if statement of the second format can be achieved.      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, a result must be returned, not a loss

The statement.

Java Fundamentals (iii)

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.