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 - Java Tutorial
From the course: Java 8 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Working with primitive variables8m 4s
-
Declaring and initializing numeric primitives6m 14s
-
Representing currency values with BigDecimal5m 10s
-
Converting numeric values5m 37s
-
Using mathematical operators and the Math class6m 1s
-
Working with Boolean values and expressions4m 49s
-
Working with character values3m 23s
-
Using Java operators6m 11s
-
-
-
-
-
-
-
-
-
-