Numbers

The computer can also do regular math that you see in school. Use System.out.println to print out the result from the math expressions.

System.out.println(5 + 4);
System.out.println(6 * (9 - 7) / 3);

Here is the full list of math symbols that you can use:

+Add\Divide
-Subtract%Modulo (remainder)
*Multiply(,)Parenthesis

Fun Fact: Computer Division

The computer does division differently from your regular calculator. Computer division will exclude remainders or decimals. For example, 15 / 4 produces 3, and not 3.75.

Working Together

Try printing out the answers to the following to the console. Ensure your brackets are matched. Use a calculator (or mental math) to verify the computer produced the correct answer.

  • 2 - 19
  • (3 + 5) * 6
  • (13 + 5 * 8) / (6 - (3 + 7))
  • 3 % 2