An explanation of the math class in Java

Source: Internet
Author: User
Tags mathematical functions

The math class contains the methods required to complete the basic mathematical functions. These methods can be divided into three types: trigonometric functions, exponential function methods and service methods. The PI and e two double constants are defined in the math class.

Pi is the value of π, and E is the value of the e index bottom, respectively: 3.141592653589793 and 2.718281828459045;

    • Trigonometric methods

The Math class contains the following trigonometric function methods:

    1. Math.todegrees This method converts the Radian value between-Π/2 to π/2 into degrees, for example: Math.todegrees (MATH.PI/2) result is 90.0;
    2. Math.toradians This method is to convert degrees to radians between-Π/2 and Π/2, for example: Math.toradians (30) results are Π/6;
    3. The three methods of Math.sin, Math.Cos and Math.tan are sine and cosine and tangent in trigonometric functions, whereas Math.asin, Math.acos and Math.atan are their inverse functions;
    • exponential function method

There are five methods in the Math class that are related to exponential functions math.exp (a) method mainly obtains the value with the base of e as exponent; Math.log () and MATH.LOG10 () are logarithmic functions; Math.pow (A, A, b) is a value of the bottom ; Math.sqrt () is a radical.

    • Rounding Method

The math class contains five rounding methods: The Math.ceil () method is to take a value to Dali, Math.floor () method is to take the value of the small inside, Math.rint () method is rounding method to take value, The Math.Round method is divided into two types of int and long, and Math.Round (a) is Math.floor (a+0.5).

    • MIN, Max and ABS methods

I don't explain these three ways, they are the maximum and the minimum and the absolute value.

    • Random method

The generation of random number values ranges from 0.0 to 1.0 for double type values. You can also use simple expressions to generate random numbers of any range, for example: (int) (Math.random () *10) returns a random integer from 0 to 9.

Like Java programming Children's shoes, No.: Mjx_ java. Can pay attention to this platform, mainly to explain some good Java in the blog and information, in an update every day, we take a look at the car when the time to take a look at the car, can pass the time, but also to increase their Java knowledge, but also hope that we can communicate more in the platform, the increase in knowledge from the Exchange, If you have a good blog post or write your own article can also be sent to small, let the small part of the publication, will be labeled on the sender's name.

An explanation of the math class in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.