CSE 131 Lab 1: Solutions to Practice Problems

Be sure to ask if you are surprised by any of these answers.
1. a. -4

 b. 4

 c. 135

 2. a.

 b.

 3.
  a. this string has spaces
  b. thisstringhasnospaces
  c. the sum of 6 + 10 is 16
  d. the sum of 6 + 10 is 16
  e. 16 equals 16
  f. 6+10 equals 610

4.
  a. false
  b. true
  c. true
  d. true
  e. true
  f. true

5.
  a. int 3
  b. double 3.5
  c. boolean false (7/2 uses integer division so the result is 3)
  d. String "x = 6"
  e. String "6 = x"
  f. error -- division by zero
  g. int 0 (due to truncation from integer division)

6. (Other answers are possible.)
  a. Math.PI * r * r
  b. 2 * Math.PI * r
  c. 2 * (h + w)
  d. Math.PI * r * r * h
  e. Math.sqrt(h*h + w*w)
  f. h * w / 2.0

7.
x y x AND y x OR y
true true true true
true false false true
false true false true
false false false false