Common methods for the math class (Java)

Source: Internet
Author: User

Trigonometric functions: public static double sin (double radians) public static double cos (double radians) public static double tan (double Radi ans) public static double Toradians (double degree) public static double Todegrees (double radians) public static double ASIN (double A) public static double ACOs (double b) public static double Atan (double A) "sin, cos, and tan parameters are all angles in radians." The return values for ASIN, ACOS, and Atan are a radian value between-Π/2 and Π/2. 1 degrees equivalent to π/180 radians, 90 radians equivalent to Π/2 radians "Example: Math.todegrees (MATH.PI/2) returns 90.0math.toradians (RETURNSΠ/6MATH.S) In (0) returns 0.0math.sin (Math.toradians) returns-1.0math.sin (MATH.PI/6) returns 0.5math.sin (M Ath. PI/2) returns 1.0MATH.COS (0) returns 1.0math.cos (MATH.PI/6) returns 0.866math.cos (MATH.PI/2) ret Urns 0math.asin (0.5) RETURNSΠ/6
exponential function: public static double exp (double x) ' e^x ' public static double log (double x) ' ln x ' public static double lo G10 (Double x) "LOG10 (x)" public static double pow (double A, double b) public static double sqrt (double x) For example: M ATH.EXP (1) returns 2.71828math.log (MATH.E) returns 1.0MATH.LOG10 (Ten) returns 1.0MATH.POW (2, 3) RET Urns 8.0math.pow (3, 2) returns 9.0MATH.POW (3.5, 2.5) returns 22.91765MATH.SQRT (4) returns 2.0MATH.SQRT ( 10.5) returns 3.24
Rounding Method: public static double Ceil (double x) "Rounding up" public static double floor (double x) "Rounding down" public static double R int (double x) "takes the nearest integer, if there are two equally close integers (. 5), take a random" public static "in bothint round (float x)/* Return (int) Math.floor (x + 0.5) */public staticLong Round (double x)/* Return (Long) Math.floor (x + 0.5) */For example: Math.ceil (2.1) returns 3.0math.ceil (2.0) returns 2.0math.ceil ( -2.0) Returns-2.0math.ceil ( -2.1) Returns-2.0math.floor (2.1) returns 2.0math.floor (2.0) returns 2.0math.floor ( -2.0) Returns-2.0math.floor ( -2.1) returns-3.0math.rint (2.1) returns 2.0math.rint (-2. 0) Returns-2.0math.rint ( -2.1) returns-2.0math.rint (2.5) returns 2.0math.rint (3.5) return S 4.0math.rint ( -2.5) returns-2.0math.round (2.6f) returns 3//returns INTMATH.ROUND (2.0) returns 2//RE Turns Longmath.round ( -2.0f) returns-2 Math.Round ( -2.6) returns-3

Overloaded method ABS returns the absolute value of a number (int, long, float, double), such as: Math.Abs ( -2.1) returns 2.1; Math also has Max and Min methods, compared to two numbers
Since 0 <= math.random () < 1.0, if 0 ~ 50 random numbers are required, then (int) (Math.random () * (50 + 1)) "Remember + 1", Random lowercase letter (char) (' a ' + Math.random () * (' Z '-' a ' + 1))

From for notes (Wiz)

Common methods for the math class (Java)

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.