java_types-variables-operators_fall2024
java_types-variables-operators_fall2024
– double x = 3 / 2 + 1;
• System.out.println(‘’x = ’’+x);
– double y = 3 / (2 + 1);
• System.out.println(‘’y = ’’+y);
Order of Operations – Cont.
Order of Operations – Cont.
• The binary arithmetic operators *, /, and %, have
lower precedence than the unary operators ++, --
, and !, but have higher precedence than the
binary arithmetic operators + and -.
• When binary operators have equal precedence,
the operator on the left acts before the
operator(s) on the right.
Sample Expressions
Increment (and Decrement)
Operators
• Used to increase (or decrease) the value of a
variable by 1
• Easy to use, important to recognize
• The increment operator
count++ or ++count
• The decrement operator
count-- or --count
Increment (and Decrement)
Operators
• Equivalent operations
count++;
++count;
count = count + 1;
count--;
--count;
count = count - 1;
Examples
• int k=0, y=0, x;
• x = ++k-y;
• System.out.println("x's value : "+x);