Think in java 答案_Chapter 3_Exercise 1

来源:互联网 发布:用ipad怎么看淘宝直播 编辑:程序博客网 时间:2024/05/01 17:24

阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx

/****************** Exercise 1 ******************
* There are two expressions in the section
* labeled "precedence" early in this chapter.
* Put these expressions into a program and
* demonstrate that they produce different
* results.
***********************************************/

public class E01_Precedence {
  static int a,
    x = 40,
    y = 60,
    z = 10;
  public static void main(String[] args) {
    a = x + y - 2/2 + z;
    System.out.println(a);
    a = x + (y - 2)/(2 + z);
    System.out.println(a);
  }

//+M java E01_Precedence

**Results are 109 & 44. The difference is because the default order of evaluation is changed by the use of the parentheses.

原创粉丝点击