From the course: Java 8 Essential Training

Unlock the full course today

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

Using mathematical operators and the Math class

Using mathematical operators and the Math class - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Using mathematical operators and the Math class

- Java supports the standard mathematical operators that you'll expect to see in all programming languages. But it also supports more complex operations using a special class called Math. I'm working in the Math project now and I've started by declaring two integer values. I'll add them together using code that's pretty intuitive. I'll declare another integer and I'll name it result1 and I'll get its value by adding intValue1 and intValue2 using the + operator. Then I'll output to the console and I'll use a label of "Addition: " and I'll append my result. I'll run that code and I'd get back an expected result. Now, I'm going to copy and paste these lines of code four times and I'm going to use four other operators. Then I'll change the operators that I'm using. I'll use the subtraction operator, the multiplication operator, the *, division which is a / and remainder which is a % character. Then I'll change the labels to match the operators and I'll run the code. For the first three…

Contents