Java math class methods

Source: Internet
Author: User
Tags natural logarithm
/* Java. the math class in the lang Package provides constants * and contains * methods for performing basic mathematical operations, such as Elementary Indexes, logarithm, and square root * for more advanced mathematical operations. * Because the methods in the math class are static, you can call * Math directly through the class. cos (angle); * (using the language feature of static import "Import static Java. lang. math. * "* You don't have to write math before every mathematical function. This allows you to call methods in the math class by a simple * name, for example, "cos (sngle )"! **/Public class Hello {public static void main (string [] ARGs) {/* 1. constant and Basic Method * Math contain two constants * 1> math. e: represents the base number of the natural logarithm. Double type * 2> math. pi: circumference rate. The double type * Math class contains more than 40 static methods */Double A =-191.635; Double B = 41.94; int c = 27, D = 65; system. out. printf ("%. the absolute value of 3f is %. 3f % N ", A, math. ABS (a); system. out. printf ("ratio %. the smallest integer of 2f is %. 0f % N ", B, math. ceil (B); system. out. printf ("ratio %. the maximum integer of 2f is %. 0f % N ", B, math. floor (B )); /* exponent and logarithm Method * exp natural logarithm E Power * log parameter natural logarithm * The second power of the first parameter of Pow * SPRT returns the square root of the parameter */double X = 12.715; double Y = 3.96; system. out. printf ("the base of the natural number is: %. 4f % N ", math. e); system. out. printf ("exp (%. 3f) is %. 3f % N ", X, math. exp (x); system. out. printf ("log (%. 3f) is %. 3f % N ", X, math. log (x); system. out. printf ("SQRT (%. 3f) is %. 3f % N ", X, math. SQRT (x);/** Random Number * random () of the math class () the static method returns a random number * between 0.0 and 1.0. The range contains 0.0, but not 1.0. * if you want to generate a 0-9 integer * You can use int number = (INT) (math. random () * 10) */system. out. print (INT) (math. random () * 10 ));}}
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: 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.