Introduction to Java Tutorial (iv) Basic syntax (2)

Source: Internet
Author: User
Tags arithmetic operators logical operators true true
# # #基础语法 (2) # # #

1. Assignment operators

Basic assignment Operator: =

Extended assignment Operator: +=,-=,*=,/=,%=

(Add/Subtract the value to the left of the equals sign and to the right of the equals sign ...). The result of the assignment equals the variable to the left)

We can see here a + = 10 equals to a = a + 10

2. Keyboard entry: Provides a class through Java---Scanner: text scanner

Basic format:

Scanner Scanner = new Scanner (system.in);

There will be an error, here we need to import a package, written between the packages and class

int number = Scanner.nextint (); "Call Scanner Method"

Here we give the example: the maximum value of the three numbers to be entered

3. Logical operators

Basic logical operators: Logic and-&, Logic, or-| , logic or-^, logical non-!

&: false False |: True True

^: The same as false differs to true

!: Not false true, false if not true, even number not for itself

difference between && and &: If False first occurs, the back of the non-execution is the effect of the rear

|| Difference from |: If first appears true then the back of the non-execution is the effect of the rear

4. Arithmetic operators

+,-,*,/,% (Take surplus)

++/--self-increment 1 or self-minus 1

Special: If ++/--data before the operation: Increment 1 or decrement by 1, then the operation (Assignment)

If the ++//participates in the operation after the data: the first operation (Assignment), then the participating operation

5. Ternary operator:? True:false

Example: Comparing three number sizes

6. Select the IF statement for the structure statement

1) if (conditional sentence) {}

Example: Enter a number when the output is greater than 8 o'clock, when it is less than 8 o'clock end.

2) if () {}else/if () {}else if

if (statement) {statement 1}else{Statement 2}

Example: Enter 1-24 to determine the time of the afternoon of the evening

# # # #END # #

Related articles:

Introduction to Java Tutorial (ii) installation using Eclipse

Introduction to Java Tutorial (iii) Basic syntax (1)

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.