Java Basics-----Operator expressions and branching structures

Source: Internet
Author: User
Tags arithmetic operators

An. operator
1. Arithmetic operators: +,-, ,/,%,++,--
2. Relational operators: >,<,>=,<=,==,!=,
3. Logical operator: &&,| |,! ,
4. Assignment operator: =,+=,-=,
=,/=,%=
5. String connector: +
6. Three mesh/conditional operator: Boolean number 1: Number 2
Note: The 1 self-increment operator is used alone, indicating that the result plus or minus one
The self-increment operator operation is divided into 2 cases, if the symbol is preceded by self-increment or decrement before the external operation, if the symbol after the first external operation and then the self-increment decrement operation.
2.&& (and), when the two sides with the true time is false, when the false is false.
3.| | (not), when both sides are false, when the truth is true.
4. Short circuit logic, &&,| | operator, when the first operand is able to determine the value of the entire expression, the second operand is not executed.
5. Extension operators such as a+=1 represent A=a+1, other
6. String connector, when a string appears in the println () bracket + represents the connector, from the beginning of "" is treated as a string concatenated.
7. Three mesh operator, when the operand before the question mark is ture, the number to the left of the semicolon is executed, and the number to the right of the semicolon is executed if the question mark is before the operand is false.

                    下面看一些代码:                int a = 5,b=5;                System,out,println(a++);//输出结果为5                System.out.println(a);//输出结果为6                System.out.println(++b);//输出结果为6                int c = a>b&&++a>b?a:b                System.out.println("a="+a+",b="+b+",c="+c)//输出结果为a=6,b=6,c=6.短路运算++a>b没被执行                System.out.println(10+20+" "+30)//输出3030                System.out.println(10+" "+20+30)//输出102030                二.分支结构            1if语句,if(boolean){            }如果括号里为ture则执行中括号里面的内容,反之则不执行。            2if---else语句,if(){            }            else{            }            如果if括号里为true,则执行if中括号里的内容,反之则执行else中括号里内容。

Java Basics-----Operator expressions and branching structures

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.