04 Lesson - Basic Input output
04 Lesson - Basic Input output
Minds On…
Calculate the perimeter and area of the circle with radius 10 cm.
Action …
Evaluating Expressions and Operator Precedence
Key Point
● Addition and subtraction operators are applied last. If an expression contains several
addition and subtraction operators, they are applied from left to righ
Here is an example of how an expression is evaluated:
The operators +, -, *, /, and % can be combined with the assignment operator (=) to form
augmented expressions.
● = x + 5 i equiva t x + 5
s lent o =
x
● = x - 5 i equiva t x - 5
s lent o =
x
● = x * 5 i equiva t x * 5
s lent o =
x
● = x / 5 i equiva t x / 5
s lent o =
x
● = x % 5 i equiva t x % 5
s lent o =
x
Increment and Decrement Operators
Key Point
The increment (++) and decrement (--) operators are for incrementing and
decrementing a variable by 1.
++i increments i by 1 and --j decrements j by 1. These operators are known as prefix
increment (pre-increment) and prefix decrement (pre-decrement).
4
Assessment
1. How would you write the following arithmetic expression in Java?
int a = 6;
a -= a + 1;
System.out.println(a);
a *= 6;
System.out.println(a);
a /= 2;
System.out.println(a);