Java.lang Math Class

Source: Internet
Author: User
Tags abs square root

In the process of programming, we often perform mathematical operations on some numbers, such as what we want to ask for absolute or cosine. Do these methods need to be implemented by ourselves? In fact, the math class math class in Java.lang contains methods for performing basic mathematical operations, such as elementary exponents, logarithms, square roots, and trigonometric functions. Let's learn it!

Let's meet some methods:

Method return Value Function description
Sin (double numvalue) Double computes the sinusoidal value of the angular NumValue
cos (double numvalue) Double computes the cosine of the angular NumValue
ACOs (double numvalue) Double computes the inverse cosine of the NumValue
ASIN (double numvalue) Double computes the inverse chord of the NumValue
Atan (double numvalue) Double computes the inverse tangent of the NumValue
Pow (double A, double b) Double calculates the B-side of a
sqrt (double numvalue) double computes the positive square root of a given value
ABS (int numvalue) int computes the absolute value of the int type NumValue, and also receives parameters of type long, float, and double
Ceil (double NumValue) double returns the smallest integer value greater than or equal to NumValue
Floor (double NumValue) double returns the maximum integer value less than or equal to NumValue
Max (int A, int b) int returns large values in int A and B, and also accepts parameters of type long, float, and double
MIN (int a, int b) int returns the smaller values in a and B, and can also accept parameters of type long, float, and double
Rint (double NumValue) double returns the integer value closest to NumValue
Round (T Arg) arg returns a long when it is double and returns an int when float returns the integer value closest to arg
Random () Double returns a double with a positive number greater than or equal to 0.0 and less than 1.0
Above are some common methods, if the students will use the polar coordinates, logarithms, etc., go to check the manual it.

Let's take a look at the sample code for some of the methods:

public class Mathtest {
public static void Main (string[] args) {
System.out.println (Math.Abs (-12.7));
System.out.println (Math.ceil (12.7));
System.out.println (Math.rint (12.4));
System.out.println (Math.random ());
}
}
Input Result:

Java.lang Math Class

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.