Task 5 of 14 · 0 solved · 14 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

1.4 Arithmetic — precedence and order

Lesson

Precedence and order

*, /, and % are done before + and -. Parentheses go first of all. Operators of equal precedence are done left to right.


Worked example

System.out.println(2 + 3 * 4);    // 14  (multiply first)
System.out.println((2 + 3) * 4);  // 20  (parentheses first)
System.out.println(10 / 2 * 5);   // 25  (left to right)
System.out.println(8 - 3 - 2);    // 3   (left to right)

▶ Try it: run this, then change something and run it again.



What is 2 + 3 * 4?


What is (2 + 3) * 4?


Type exactly what this prints:

System.out.println(10 - 2 * 3);

What is 10 / 2 * 5?


Java evaluates 2 + 3 * 4 - 1 step by step. Put the steps in the order Java performs them.