Introduction
Operator precedence tells the computer which math or logic operation to do first when there are many in one line.
result = expression_with_operators;
int result = 2 + 3 * 4;
int result = (2 + 3) * 4;
boolean check = true || false && false;
boolean check = (true || false) && false;
public class OperatorPrecedenceDemo { public static void main(String[] args) { int a = 5 + 2 * 3; // 2*3=6, then 5+6=11 int b = (5 + 2) * 3; // 5+2=7, then 7*3=21 boolean c = true || false && false; // false && false = false, then true || false = true boolean d = (true || false) && false; // true || false = true, then true && false = false System.out.println("a = " + a); System.out.println("b = " + b); System.out.println("c = " + c); System.out.println("d = " + d); } }
3 + 4 * 5?int x = 2 + 3 * 4 - 6 / 2; System.out.println(x);
int a = 5; int b = 10; int c = a + * b;
int result = 10 - 2 * 3 + 4 / 2;
Pass the test and this pattern moves unknown