Friday, May 30, 2008

W6 Problem 3

Problem 3 (R4.16)

Note: Appendix E of the textbook contains a chart showing the order of precedence of Java operators.

What are the values of the following expressions? In each line assume that

double x = 2.5;

double y = -1.5;

int m = 18;

int n = 4;

String s = “Hello”;

String t = “World”;

  1. x + n * y – ( x + n ) * y

  1. m / n + m % n

  1. 5 * x – n / 5

  1. Math.sqrt(Math.sqrt(n))

  1. (int) Math.round(x)

  1. (int) Math.round(x) + (int) Math.round(y)

  1. s + t

  1. s + n

  1. 1 – ( 1 – ( 1 – ( 1 – ( 1 – n ))))

  1. s.substring(1,3)

  1. s.length() + t.length()

No comments: