Learning Java--- Understanding Java Math Methods.

in GEMS4 years ago

Hello people

In the previous post of Java tutorials, we have discussed Java Strings and String Methods. We have discussed some useful methods of class String. In the upcoming post, we will discuss the Java further by step by step. We have already and almost covered the javascript basic course. Just a few things remaining in the basic course. You will cover that very soon. Today we are going to discuss another class and its method. Understanding Method in Java is really important it helps us a lot while solving problems. We are going to discuss the class Math. ( We will learn about what is class later in the tutorials but for now, focus on this topic). So let's start our tutorial
java_binary_code_gears_programming_coding_development_by_bluebay2014_gettyimages-1040871468_2400x1600-100795798-large.jpg
Image source

Java Math

The Java Math class contains many methods that allow us to perform mathematical operations. We will discuss some useful and important Methods of class Math here.

1. Math.abs()

This method returns the positive of the number passed through its parameter. It takes one argument and returns it positive.

image.png

As you can see in the above snap, we are passing a negative value through Math.abs and it is returning it as positive.

Math.max()

The Math.max() Method takes two numbers and returns the highest number.Or it compares two numbers and returns grater number For example

image.png

In the above snap, we have passed two values and it is printing the highest value on the console,

Math.min()

Math.min() return the minimum number. It takes two values and can find the minimum among them. For example

image.png

  • One more thing I want to add here is you are storing the number in a variable the then you have to specify whether the value of float, int, or double. if you create an integer varable and then try to store the floating or double value give you errors.

image.png

As you can see the IDE is suggesting the options

Math.squrt

This method takes one number and returns its square root. This method is one of the important Methods of Math class. It helps us solve the mathematical problems in less time. For Example

image.png

Math.random()

This method takes no argument. This will return a random number from 0 to 1.

Screen Recording 20200423 at 03.31.15.23 AM.gif

  • There are a lot of methods in Math Class. The basic but important are already discussed here

image.png

but there are many which are important as well I want you to take a look at them and understand them. If you face any problem feel free to ask in the comment.

That's all. If you like the post don't forget to upvote and comment. Thank you

ntitled-1.png

Sort:  

Thanks for sharing your creative and inspirational post on HIVE!



This post got curated by our fellow curator @tibfox and you received a 100% upvote from our non-profit curation service!

Join the official DIYHub community on HIVE and show us more of your amazing work!

Thank you for your support.