Java Foundation---Operator precedence in Java (16)

Source: Internet
Author: User

Precedence of operators in Java

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:

650) this.width=650; "src=" http://img.mukewang.com/5360ffb90001b4f002620224.jpg "/>

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:

650) this.width=650; "src=" http://img.mukewang.com/5361000a000129a005060071.jpg "/>

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


Code:

public class HelloWorld {
public static void Main (string[] args) {
int m = 5;
int n = 7;
int x= (m*8/(n+2))%m;
System.out.println ("M:" + M);
System.out.println ("N:" + N);
System.out.println ("x:" + x);
}
}

Operation Result:

M:5
N:7
X:4

This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547682

Java Foundation---Operator precedence in Java (16)

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.