Expressions Practice

Expressions Practice#

These questions are to assess your understanding of Java expressions.

For each question, answer with the value that would result from fully evaluating that expression. Remember some of the tricky aspects of expressions in Java:

  • [!] [P] [MMD] [AS] [<><=>=] [== !=] [&&] [||] precedence!

    • When there are multiple operations at the same level of precedence, they are executed left to right in order.

  • Keep track of the type of each subexpression as you work through each problem!

  • Watch out for that pesky int division!

Note

Make sure your answer conveys the appropriate type of the result in each answer. For double results, include the decimal point (even if the answer is a whole number, such as 7.0 instead of 7). For String results, surround the value with double-quotes (such as “hi 23”).

Questions 1

3 * 10


Question 2

"cat" + "dog"


Questions 3

11 % 3


Question 4

(2 + 3 * 6) % 3


Questions 5

12 / 5 + 8 / 4


Question 6

(14 / 5 + 7 * 3) % 8 > 4


Questions 7

12.0 / 5


Question 8

"hello" + 2 + 3


Question 9

2 + 3 + "hello"