yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Java Lesson 6 | java.lang.Math


4m read
·Nov 3, 2024

Hey, this is Jake. I'm a special guest of Maads 101, and in this Java tutorial, we'll be talking about this right here:

import java.math.*;

With a capital M, and this allows us to do some more math stuff besides just add, subtract, multiply, and divide. So if you want to start making some programs, uh, with some formulas, it's going to help you a lot.

I'm not really going to be making a program here; I'm just going to be printing out a bunch of um, stuff, basically. That I'll take a number and use one of the methods on it, or some of them don't take any arguments, but I'm just going to be printing a bunch of stuff out.

So just that out:

System.out.println();

And I'm just going to copy and paste this a bunch of times, right? I have a lot of methods; I'll see if I'm using them all.

Probably going to wind up using more. So, the first one I'm going to show, yeah, I'm going to be using more, um, is Math and to use all these, you do Math.PI, in caps.

And that Math.PI um, is just basically, you can use that as Pi. Same kind of thing with Math.E, and that's E. So this would print out Pi and it would print out E, and um, Math.random() and you put those empty parameters there, and that will just print out a random number just out of the blue.

Um, Math.abs() and I'll put in -5, and Math.abs() gets the absolute value of something. Yeah, I'm going to be going over these real quick, and if you don't know what some of them are, um, just don't worry about it because you're probably not going to be um, using them right now.

So I'm just going to go over just what kind of stuff there is in there. Then you have um, Math.round() and I'll just put 0.6, and that will round. And this is in parentheses, by the way, and that will round 0.6, and that should be 1.

Um, Math.max() and this requires explaining. Um, you put in two numbers and it will um, get the highest one. So like 15, comma, 10, and that would do 15, 'cause 15 is higher than 10.

And the opposite is Math.min(), so if I did 15, comma, 10, it would get the lowest of the two, which is 10. Alright, um, next here, I'm just going to copy and paste this a couple more times. Alright, and so now the next one is square um, square root.

Then I'll do cube root. So Math.sqrt() and that will get you the square root of something. I'll just put 100 because that's nice and easy.

And Math.cbrt() will be the cube root, and I'll do 64 because that is also nice and easy. So that would be 10, and that would be 4. So Square root of 100 and cube root of 64.

Math.sin() I'll just do sin(10), and of course, there's also Math.cos(), I'll do that of 10 too. And if there's cosine and sine, of course, tangent.

I'll do the tangent of 10. So to get to use sine is Math.sin(), Math.cos(), Math.tan(). If you're going to be doing some trig kind of stuff, um, there’s Math.pow(), and this takes two things, and this is for exponents.

One is your number, so I'll do like 6, and I'll do 2. And what this would do is take the number 6 and raise it to the power of 2. So the second number is the exponent you're going to put on this number here, so 6^2, 6 squared, which is 36, and that's what that'll do.

And then um, the last one I'm going to show, or last two are for logarithms: Math.log() and in here, and that's going to be using um, log. The base with just Math.log is E, it's the base it’s going to be using, so I'll just do like Math.log(12); doesn't matter.

And System.out.println(). This is the last one: Math.log10(), and that will be using 10 um as the logarithmic base, and I'll do 12 again.

Alright, so let me just review this one more time. Um, Math.PI, which is pi, Math.E, which is E, Math.random(), which is a random number, Math.abs(), we'll get to the absolute value, Math.round(), we'll round a number, Math.max() will get you the higher of two values, Math.min() will get you the lower of two values, Math.sqrt() will get you the square root of a value, Math.cbrt() will get you the cube root of a value, Math.sin() will get you the sine, Math.cos() will get you the cosine, Math.tan() will get you the tangent, Math.pow() will raise the first number to the power of the second number, and Math.log() will um, just regular log is with the base of E, and Math.log10() is with um, a base of 10.

So I'm just going to run all this, and you'll see. Alright, so that's Pi, that's E, that's a random number, that's absolute value -5, which is 5, it rounded 0.6 to 1, it found the greater of 10 and 15, which is 15.

Then it found the lesser of 10 and 15, which is 10. It got the square root of 100, which is 10, it got the cube root of 64, which is 4, and I got the sine of 10, the cosine of 10, the tangent of 10.

It did 6^2, which is 36, and that did log(12) with the base of E, and then log(12) with the base of 10.

So that is just some stuff you can use, so um, see you next time.

More Articles

View All
Interpreting change in exponential models | Mathematics II | High School Math | Khan Academy
So I’ve taken some screenshots of the Khan Academy exercise interpreting rate of change for exponential models in terms of change. Maybe they’re going to change the title; it seems a little bit too long. But anyway, let’s actually just tackle these togeth…
15 Types Of People YOU NEED TO AVOID
It is not a strange thing to say that the type of people you surround yourself with have a significant impact on your life. After all, a lot of your time will be spent with them, and it is only natural that their habits and the things they say would affec…
'Property is theft' stolen concept fallacy
Property is theft. This is a phrase that unpacks as all property is theft, and it’s something that I’ve seen mentioned a few times on YouTube lately. A comment from one of my subscribers, I think in my previous video, prompted me to address this specifica…
Comparing P-values to different significance levels | AP Statistics | Khan Academy
What we’re going to do in this video is talk about significance levels, which are denoted by the Greek letter alpha. We’re going to talk about two things: the different conclusions you might make based on the different significance levels that you might …
Node voltage method (steps 1 to 4) | Circuit analysis | Electrical engineering | Khan Academy
We’re going to talk about a really powerful way to analyze circuits called the node voltage method. Before we start talking about what this method is, we’re going to talk about a new term called a node voltage. So far, we already have the idea of an elem…
THIS Common Mistake Ruins Small Businesses | Tom Segura
But within families, there’s always ego intention. Always. There’s the brother, the sister, the mother, the cousin, whatever. If you are unable to fire your own mother, you shouldn’t run the family business because you’ve got to think about the business f…