293,286 views
2 votes
2 votes
Trace the evaluation of the following expressions, and give their resulting values. Make sure to give a value of the appropriate type (such as including a .0 at the end of a double or quotes around a String).

4 + 1 + 9 + "." + (-3 + 10) + 11 / 3
8 + 6 * -2 + 4 + "0" + (2 + 5)
1 + 1 + "8 - 2" + (8 - 2) + 1 + 1
5 + 2 + "(1 + 1)" + 4 + 2 * 3
"1" + 2 + 3 + "4" + 5 * 6 + "7" + (8 + 9)

User Joel Davey
by
2.6k points

1 Answer

27 votes
27 votes

Answer:


(a)\ 14


(b)\ 0


(c)\ 2


(d)\ 7


(e)\

Step-by-step explanation:

Required

Evaluate each expression

The simple rules to follow are:

(1) All expressions in bracket will be evaluated based on its data type

(2) Divisions will return only integer values

(3) Integers immediately after string values will be concatenated (not added)

So, the results are as follows:


(a)\ 4 + 1 + 9 +

Evaluate till a string is encountered


4 + 1 + 9 = 14

Followed by "."

Then:


(-3 + 10) = 7


11/ 3 = 3


-- because expressions after string operations are concatenated.

So, we have:


4 + 1 + 9 +


(b)\ 8 + 6 * -2 + 4 +

Evaluate till a string is encountered


8 + 6 * -2 + 4 =0


So, we have:


8 + 6 * -2 + 4 +


(c)\ 1 + 1 +

Evaluate till a string is encountered


1 + 1 = 2


So, we have:


1 + 1 +


(d)\ 5 + 2 +

Evaluate till a string is encountered


5 + 2 =7


--- multiply 2 and 3, then concatenate

So, we have:


5 + 2 +


(e)\

Since a string starts the expression, the whole expression will be concatenated except the multiplication and the expressions in bracket.

So, we have:


User Felisha
by
2.9k points