Java Programming- How to use math class functions or methods tutorial

Java Programming- How to use math class functions or methods tutorial


Hello guys! My name is Akshay. Today I am
going to tell you how to use some basic math functions. First function is Math.pow.Pow as in power. For example 2^3, 2^4, 3^2, 3^4, 4^1, 4^2,
8^9….anything. So, here what I am d.oing is 2^2 is 4. See! You can also do it like this.
You can just give a number It doesn’t have to be a variable. 2^5=32; The same can be done like this So.. this is a code…..this is the code for power Okay!Let me go to the next one. Absolute value!Absolute value is none other than modulas. So the number you give is 8.2343.The
value it prints is 8.2343. So, here the number I want to check in absolute value is 2.8215. let’s see how it performs… 2.8215! so what happens if it is a negative value? Let’s see. Again 2.8215! A positive 2.8215.
That’s exactly what this absolute value does. it changes the negative value into a positive
value. It does not make any change to a positive value. What happens if b=0? Let’s check it
out. 0.0! So I think your doubts are clear. Math.ceil! This is really simple. The number
here is 2.5213. Then ceil should be 3. But don’t confuse it with round.Math.round. Math.round,what
it does is that, if it is more than 2.5 or equal to 2.5, it converts it to 3 and less
than 2.5 it converts it to 2. But here let’s see what happens. Again 3! So what does that
mean. It means it will convert it to the number, an integer that is greater than the value
you have posted. For this value, the integer that is closest as well as greater than b
is 3. Let’s go to the next one. Math.floor! Math.floor is the exact opposite
of Math.ceil. Floor means it gives the integer that is nearest to the value and also lower
than the value. So, let’s check it out. Floor=2. We’ll check it with a number where rounding
off gives a different answer. Again 2. So I think your doubts are cleared. Let’s go
to the next one. Math.sqrt. Sqrt is basically square root.so
the number you give is 2…..wait wait wait…….. the number you give is 4. it will give 2.
but it also works for numbers 2,3,5 for whom square root is not an integer. Let’s check
it out. See! I don’t think you any problems in sqrt. So, I am going to the next one.
Minimum value. Minimum value, you have 2 numbers; you compare them; and the lowest number is
printed; a=2 and b=208213. The minimum value is … yeah! you guessed it right! 2.
And the next one is the exact opposite. Math.max. Here, it gives the maximum value. So if you
compare 2 numbers it gives the number that is greater than the other number.Again a and
b are the same. We have 2.8213.See! It gives the max value. That’s all for today folks!
Thank you! Please Subscribe!

1 thought on “Java Programming- How to use math class functions or methods tutorial”

Leave a Reply

Your email address will not be published. Required fields are marked *