Java Tutorial #8-1 / 8-2 — Using math functions with if logic

Apologies about this being a two-part video, AND for my mic volume being weird, in future videos this is fixed. I’ll consider re-recording this later

Topics Discussed: Using math functions with if-based logic to choose the output of a program

Source Code Available Here

8-2 Here

Topics discussed: Same as above

Source Code Available Here

In these videos I talk a little bit about java.lang.Math; An include that allows us to do some simple mathematical calculations in our code in conjunction with the if-statements we’ve been talking about.

java.lang.Math functions
There are a LOT of different constructs in the java.lang.Math library, but the ones we use in this lesson seem to be the most common of them. Raising a number to a power, and taking the square root of a number. The code for each of these is as follows: (assuming you have the import in your code)

Math.pow(numberOrVariable, powerRaisingTo);
Math.pow(x, 3); // raises x to the 3rd power.

Math.sqrt(x); //Takes the square root of x.