Skip Top Navigation Bar

Experiment with Arithmetic Basics

Using Java Playground

In this activity, you will make predictions regarding the outcome of given expressions. You will use the Java Playground to test your predictions.

There are two ways you can enter expressions into the Java Playground.

Detailed Output ON Detailed Output OFF
With this option, enter each expression with a ; at the end and get a return value, as follows: With this option, put each expression in an output statement, as follows:

Directions

  1. Take some time to predict the value of each arithmetic expression. Record that value in the Predicted Value column.
  2. Once you have recorded all your predictions, enter each expression into the Java Playground and record the value in the Actual Value column.
  3. For any expression where your prediction and the actual value differs, write an explanation of how the expression is evaluated.
  4. Write a definition of each arithmetic expression and provide your own example.

Predict and Try

Java Expression Predicted Value Actual Value Explanation of Differences
4 + 5
4.0 + 5.5
4 - 5
5.5 - 4.0
3 * 5
3.0 * 5.0
4 / 2
3 / 2
4.0 / 2.0
3.0 / 2.0
4 % 2
3 % 2
7 % 4
2 + 3 * 5
(2 + 3) * 5
(2 + 3) * (5 / 2)
2 + (3 * 5) / 2
"Hello" + 5 + 2
"Hello" + (5 + 2)
5 + 2 + "Hello"

What does each arithmetic Operator do?

For each operator, write a description of what it does and provide your own example.

  1. +
  2. -
  3. *
  4. /
  5. %
  6. ( )