Java's math class

Source: Internet
Author: User
Tags acos hypot natural logarithm pow value of pi

Java's math class Java's math class encapsulates a lot of math-related properties and methods, and subsequent encounters commonly used will be directly updated in this blog ...
public static void T2 () {System.out.println (MATH.E);//A double value that is closer to E (that is, the base of the natural logarithm) than any other value.    System.out.println (Math.PI);//is closer to the double value of PI (that is, the ratio of circumference to diameter of the circle) than any other value. /* * 1.abs absolute value function * Absolute value for various data types/SYSTEM.OUT.PRINTLN (Math.Abs (-10));//Output 10/* 2. Trigonometric functions and Inverse trigonometric function * CO s cosine * sin seeking sine * tan seeking tangent * acos Negation cosine * ASIN seeking inverse sine * atan seeking inverse tangent * atan2 (y,x    . OUT.PRINTLN (Math.acos (-1.0));//output Pi 3.14 ... System.out.println (Math.atan2 (1.0, 1.0));//output Π/4 Small value//* 3. Open Radical Root * CBRT (x) Open cubic * sqrt (x) Open square * Hypot (y sqrt (x*x+y*y) is useful sqrt ((x1-x2) ^2+ (y1-y2) ^2)/System.out.println (MATH.SQRT (4.0)) when seeking distance between two points;//Output 2.0 System.out.prin TLN (MATH.CBRT (8.0));//Output 2.0 System.out.println (Math.hypot (3.0, 4.0));//Output 5.0/* * 4. Max. * MAX (A, A, b) for maximum value *     Min (A, b) Minimum value */System.out.println (Math.max (1, 2));//Output 2 System.out.println (Math.min (1.9,-0.2));//output-0.2/* * 5. Logarithm * log (a) A's natural logarithm (base is e) * LOG10 (a) alogarithm of base 10 * log1p (a) a+1 natural logarithm * It is worth noting that other functions previously overloaded, logarithmic operations can only pass double data and return double type data */SYSTEM.OUT.PRINTLN (Math . log (MATH.E));//Output 1.0 System.out.println (MATH.LOG10 (10));//Output 1.0 System.out.println (math.log1p (math.e-1.0));//     Output 1.0/* 6. Power * EXP (x) returns the value of E^x * EXPM1 (x) returns the value of E^x-1 * POW (x, y) returns the value of X^y * The data types available here are also double type  */System.out.println (MATH.EXP (2));//output e^2 value System.out.println (Math.pow (2.0, 3.0));//Output 8.0/* * 7. Random number * Random () returns the double value between [0.0,1.0] * This generates an integer that can actually be obtained by *x control * such as (int) (random*100) after [0,100] */SYSTEM.OUT.PR INTLN ((int) (Math.random () * 100));//output [0,100] random number//ceil (a) returns the floating-point numbers corresponding to the first integer greater than a (the value is integer, the type is floating-point type)///can be converted by casting the type to integral type S Ystem.out.println (Math.ceil (1.3443));//Output 2.0 System.out.println ((int) Math.ceil (1.3443));//Output 2//floor (a) Returns the floating-point number of the first integer less than a (the value is integer, the type is float) System.out.println (Math.floor (1.3443)), or the output 1.0//rint (a) returns the double value of the integer closest to a System  . OUT.PRINTLN (Math.rint (1.2));//Output 1.0  System.out.println (Math.rint (1.8));//Output 2.0} 
Results:

Java's math class

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.