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 - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
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…
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
-
-
-
-
-
(Locked)
Work with primitive variables6m 35s
-
Declare and modify primitive values4m 48s
-
(Locked)
Store currency values with BigDecimal3m 32s
-
(Locked)
Convert values between numeric types3m 19s
-
(Locked)
Math operators and the Math class3m 11s
-
(Locked)
Work with boolean values2m 51s
-
(Locked)
Work with character values4m 12s
-
(Locked)
More about Java operators4m 48s
-
(Locked)
-
-
-