First a comment:

// System.out.println("+---+\n|   |\n+---+");
//                     0123456789012345678

The digits below the statement/string help count the spaces within.

Here are the answers let me know if more detail is needed. 

 1.  A square is printed:

> System.out.println("+---+\n|   |\n+---+");
+---+
|   |
+---+
>

 2.  The class needs to be imported:

    import java.math.BigDecimal; 

Somewhere in a method (or the Interactions Panel) we have:

    BigDecimal a = new BigDecimal("4.35"), 
               b = new BigDecimal("100"); 
    BigDecimal result = a.multiply(b);

 3. 3 - 4 + 5 is -1 + 5 which is 4

 4. 3 - 4 * 5 is 3 - 20 which is -17 

 5. 2 / 3 * 4 is 0 * 4 which is 0

 6. 2 * 3 / 4 is 6 / 4 which is 1

 7. 3 % 5 is 3 because 3 == 5 * 0 + 3 

Dividing 3 by 5 yields a quotient of 0 and a remainder of 3.

 8. -3 % 5 is -3 because -3 = 5 * 0 + (- 3)

Thus quotient is 0 and remainder -3. 

Also because (- n) % m == n % m 

 9. 5 % 3 == 2 because 5 == 3 * 1 + 2

So, quotient 1 and remainder 2.

10. 5 % (-3) == 2 because 5 == (-3) * (-1) + 2

Thus quotient is -1 and the remainder is 2. 

11. 3 % -5 is 3 because 3 == -5 * 0 + 3

So quotient is 0 and remainder is 3.

12. 49 / 17 % 5 is 2 % 5 which is 2

13. 49 / (17 % 5) is 49 / 2 which is 24

14. ('a' + 'b') % 2 is 1

The reason: ASCII codes for 'a' and 'b' differ by 1

(Specifically they're 98 and 99 but you did not need to know that).

To find the ASCII code of any character add 0 to it: 

Welcome to DrJava.  Working directory is C:\Users\cogli\Desktop
> 'a' + 0
97
> 'B' + 0
66
> '7' + 0
55


15. false || true is true (by definition)

16. ! true && false is false && false which is false 

17. ! (true && false) is ! false which is true 

18. When n is 3, n > ++n evaluates to 3 > 4, which is false.

19. When n is 3, ++n - n evaluates to 4 - 4 which is 0 (zero).

20. When n is 3, n++ == n++ evaluates to 3 == 4 which is false.

21. When n is 3, ++n == n++ evaluates to 4 == 4, which is true.

22. When n is 3, n++ evaluates to 3. 

23. When n is 3, ++n evaluates to 4.

24. When n is 3, n++ - ++n evaluates to 3 - 5 which is -2.

An assignment statement in Java is an expression. 

The value of an assignment statement is its right hand side. 

25. Clearly in 24. the value placed in n is -2.

26. "1" + (2 + 3) is "1" + 5 which is "15"

27. "1" + 2 + 3 is "12" + 3 which is "123"

28. 1 + "2" + 3 is "12" + 3 which is "123"

29. 1 + 2 + "3" is 3 + "3" which is "33"

30. "tomato".charAt(2) - "potato".charAt(5) evaluates to
     012345               012345

    'm' - 'o' which is -2 because L, M, N, O, P.

Recall Demetri Martin's joke (at the end of a letter): 

P.S. Is what the alphabet will look like if Q and R were eliminated.

31. "eggplant" is 8 characters long

32. "kale".length() is 4

"eggplant".substring(4) is "lant"
 01234567

Notice the digits below the string to help with counting.

33. "kale".charAt(3) is 'e'
     0123

34. "eggplant".substring("eggplant".length()-1) is the same as

    "eggplant".substring(8-1) which is the same as

    "eggplant".substring(7) which is the same as "t"
     01234567

35. "beans".substring(1, 4) is the same as "ean"
     01234

36. !a

37. !a

38. !a

39. a = (n == 3)

40. a = (n == 3)
 
41. a = (n == 4)

42. a == (n < 0 || n > 1)

43. true

44. false 

45. Yes and here's how (in general)

INIT
while (COND) {
  BODY
  STEP
}

becomes 

for (INIT; COND; STEP) {
  BODY
}

46. Here let's start from 

do {
  BODY;
} while (COND);

Note here BODY has to run before we evaluate COND. 

So we can write it as follows:

if (COND) {
  do {
    BODY;
  } while (COND};
}

But just because you can it doesn't mean you should. 

So the answer is yes, technically. 

But when showing how we indicate COND must be evaluated first. 

47.  1

48.  1 

Between 47 and 48 the else dangles, with no effect.

49.  2

50. 10

Between 49 and 50 the else dangles, this times with consequences.

51. See Common Error 5.2 in the text, pp. 189-190.

If someone ever asks you 

  What does "tomato" == "tomato" evaluate to? 

Your answer should be: don't know (it's unspecified). 

If there is just one string "tomato" the answer is true. 

If there are two of them the answer is "false". 

To check if two strings read the same ask them (.equals()).

52. Check What's New? for Mon Sep 12. 

--