In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the Math class of Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Java's Math class.
The Math class contains the methods needed to complete the basic mathematical functions. These methods are divided into three categories: trigonometric function method, exponential function method and service method. In addition to these methods, the Math class also provides PI (π) and E (the base of the natural logarithm) that can be used directly with Math.PI and Math.E.
Numerical operation Math class 1. Overview
From the java.lang package (core package, which provides classes critical to the design of the java programming language, which can be used directly without import)
The Math class contains methods that perform basic numeric operations, such as basic exponents, logarithms, square roots, and trigonometric functions.
Public final class extends Object2. No construction method 3. The main method static double abs (double a) returns the absolute value of double static double acos (double a) returns the inverse cosine of double static double log (double a) returns the natural logarithm of double (based on e) static double log10 (double a) returns the logarithm static int max of cardinality 10 of double (int a) Int b) returns the maximum of the two int values static double random () returns a double type value rounded up by [0pc1): static double floor (double a) returns an integer of the largest double type less than or equal to a Round down: static double ceil (double a) returns the smallest changed type less than or equal to a. Integer statisc String round (double a) returns the nearest long type in the parameter, rounding 4. Field, class variable static double E value, equivalent to e, the cardinality static double PI value of the natural logarithm, equivalent to pi, and the ratio of circumference to its diameter 5. 5. Demo case public class MathTest {public static void main (String [] args) {double a =-0.5 System.out.println double pi = Math.PI;double e = Math.E;System.out.println ("the absolute value of an is:" + Math.abs (a)); System.out.println ("the inverse cosine of pi is:" + Math.acos (pi/4)); System.out.println ("a rounded up is:" + Math.floor (a)) System.out.println (the value of "a rounded down is:" + Math.ceil (a)); System.out.println (the natural logarithm of "e is" + Math.log (e)); System.out.println (the maximum of "an and 0.5 is:" + Math.max ()); System.out.println ("a multiplied by a random value of" + Math.random () * a) System.out.println ("the long type value closest to an is:" + Math.round (a)); System.out.println ("the sine of pi/6 is:" + Math.sin (pi/6));}} at this point, I believe you have a deeper understanding of "how to use Java's Math class". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.