From the course: Oracle Java Foundations

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Operators

Operators

(bright music) - [Instructor] Operators. Up until now, we've seen how to create variables and constants and we've seen how to assign values to variables and work with constants and such, but we haven't really talked about the mathematical operators and what's available in Java. Java supports the standard mathematical operators, addition, subtraction, multiplication, and division, and examples are shown here. We'll start by assuming that we have an int result equals 0, and int num1 equals 11, and an int num2 equals 2. So now if we come to our first example, result is equal to num1 plus num2. Well, num1 has a value 11, num2 has a value 2, 11 and 2 is 13. So the value 11 and 2 is summed together, added together, and assigned a result and result becomes 13. If we then take result and add 1 to it and store it back in, it takes the value 13, adds 1 to it and stores it back into result which becomes 14. Now a shorthand way of doing this in Java is to write plus equals and it's equivalent to…

Contents