Mu Net-android engineer first form the precedence of operators in -3-9 Java

Source: Internet
Author: User

SOURCE http://www.imooc.com/code/1315

The so-called priority is the order of operations in an expression. The precedence of operators commonly used in Java is shown in the following table:

Level 1 has the highest priority, and level 11 has the lowest priority . For example, the result of x = 7 + 3 * 2 is 13 "Multiply First and add"!

PS: We don't have to go. The order of precedence of the rote operators, which is typically used to assist in priority management in real-world development. For example:

Analysis: Parentheses have the highest precedence, so

1, execute a + 18, the result is 30

2, perform (A + 18)% 4 modulo, the result is 2

3, execute A * ((A + 18)% 4), the result is 24

Task

In the editor, enter the line 5 :

int x = (M * 8/(n + 2))% m;

Combined with the results of the operation: I believe you will have a clearer understanding of operator precedence!

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3         intm = 5;4         intn = 7;5         intx = (M * 8/(n + 2))%m;6System.out.println ("M:" +m);7System.out.println ("N:" +n);8System.out.println ("x:" +x);9     }Ten}

Mu Net-android engineer first form the precedence of operators in -3-9 Java

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.