From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Math operators and the Math class

Math operators and the Math class - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Math operators and the Math class

- [Instructor] Java supports the standard mathematical operators that you'd expect to see in all programming languages, but it also supports more complex operations using a special class called math. I'll start by declaring two integer values. I'll name them intValue1 and intValue2. And I'll give them values of 56 and 42. Now, I'll do some simple addition. I'll create an integer that I'll call result1 and I'll assign it using intValue1 plus intValue2, and the result is 98. Now, I'll change this operator for the second example from a plus to a minus, now I change the name of the variable I'm creating from result1 to result2, and the result that is 14. And you can also do multiplication and division this way. As with most languages the asterisk is for multiplication and the forward slash character is for division. Now, notice that when I do division, I get a value of one, and that's because these are integer values. When you divide two values you get back an integer, and if the result…

Contents