Looking back, Java restudying (vii): operator of Java Basics

Source: Internet
Author: User
Tags arithmetic operators bitwise operators logical operators

    • Regular arithmetic operators

Include + 、-、 *,/,% respectively corresponding to add, subtract, multiply, divide, take the remainder, the arithmetic operator to handle the two numbers must be the same type, if it is different type and can not be automatic type conversion words must be forced type conversion, but forced type conversion may lose some information, there are shorthand method + =, etc. As follows:

int i = i + 1;//up and down two equations are actually the same//the corresponding other operators also have such shorthand, such as *=
int i + = 1;
    • Self-increment self-reduction

  It should be known from the programming base that adding a minus one action to a variable in a program is very common, and the self-increment decrement operator simplifies this operation, and the difficulty in this part is the effect of the position of the self-increment operator on the variables in the program, and if the self-increment-decrement is used before the variable, After the variable is the first to use the re-operation, with the following examples to illustrate:

 Public class Welcome {    publicstaticvoid  main (string[] args) {        int A = 1;             int b = 1; Output results 2, 2, 1, 2
System.out.println (+ +a); System.out.println (a); System.out.println (b+ +); System.out.println (b); } }
    • Relational operators

  include = =, <, >, >=, <=, which are used to compare size or equality, as in written use.

    • logical operators

  Includes &, &&, |, | |,!, where & and | can also be used as bitwise operators, as logical operators when both elements are Boolean,&& and | | Functions, like & and |, are short-circuit logic, that is, the first operand is sufficient to determine the value of an expression without a second operand, and most of the time it uses a short-circuit logic operation.

Another common logical operation is the ternary expression, which is the expression? Result 1: Result 2, the expression is true returns result 1, and false returns result 2, for example x<y?x:y that returns the smaller values in X and Y.

Looking back, Java restudying (vii): operator of Java Basics

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.