现在的位置: 首页 > 综合 > 正文

Think in java 答案_Chapter 3_Exercise 1

2013年06月29日 ⁄ 综合 ⁄ 共 628字 ⁄ 字号 评论关闭

阅前声明: 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.

抱歉!评论已关闭.