[Java]View PlainCopy
- Public class Mathdemo {
- public static void Main (String args[]) {
- /**
- * ABS Seek absolute value
- */
- System.out.println (Math.Abs (-10.4)); //10.4
- System.out.println (Math.Abs (10.1)); //10.1
- /**
- * Ceil ceiling means to return a large value, note some special values
- */
- System.out.println (Math.ceil (-10.1)); //-10.0
- System.out.println (Math.ceil (10.7)); //11.0
- System.out.println (Math.ceil (-0.7)); //-0.0
- System.out.println (Math.ceil (0.0)); //0.0
- System.out.println (Math.ceil (-0.0)); //-0.0
- /**
- * Floor meaning is to return a small value
- */
- System.out.println (Math.floor (-10.1)); //-11.0
- System.out.println (Math.floor (10.7)); //10.0
- System.out.println (Math.floor (-0.7)); //-1.0
- System.out.println (Math.floor (0.0)); //0.0
- System.out.println (Math.floor (-0.0)); //-0.0
- /**
- * Max two returns a large value, min and it instead, it's not an example.
- */
- System.out.println (Math.max (-10.1,-10)); //-10.0
- System.out.println (Math.max (10.7, 10)); //10.7
- System.out.println (Math.max (0.0,-0.0)); //0.0
- /**
- * Random gets a number greater than or equal to 0.0 less than or equal to 1.0
- */
- System.out.println (Math.random ()); //0.08417657924317234
- System.out.println (Math.random ()); //0.43527904004403717
- /**
- * Rint rounded, return double value
- * Note that an even number will be taken at 5.
- */
- System.out.println (Math.rint (10.1)); //10.0
- System.out.println (Math.rint (10.7)); //11.0
- System.out.println (Math.rint (11.5)); //12.0
- System.out.println (Math.rint (10.5)); //10.0
- System.out.println (Math.rint (10.51)); //11.0
- System.out.println (Math.rint (-10.5)); //-10.0
- System.out.println (Math.rint (-11.5)); //-12.0
- System.out.println (Math.rint (-10.51)); //-11.0
- System.out.println (Math.rint (-10.6)); //-11.0
- System.out.println (Math.rint (-10.2)); //-10.0
- /**
- * Round rounding, float returns int value, double returns Long value
- */
- System.out.println (Math.Round (10.1)); //10
- System.out.println (Math.Round (10.7)); //11
- System.out.println (Math.Round (10.5)); //11
- System.out.println (Math.Round (10.51)); //11
- System.out.println (Math.Round (-10.5)); //-10
- System.out.println (Math.Round (-10.51)); //-11
- System.out.println (Math.Round (-10.6)); //-11
- System.out.println (Math.Round (-10.2)); //-10
- }
- }
Common values and functions:
Math.PI recorded by pi
MATH.E Constants for Record E
There are some similar constants in math, all of which are commonly used in engineering mathematics.
Math.Abs Absolute Value
Math.sin sine function math.asin inverse chord function
Math.Cos cosine function Math.acos inverse cosine function
Math.tan tangent function Math.atan inverse tangent function math.atan2 the inverse tangent function of the quotient
Convert math.todegrees radians to angles math.toradians angles to radians
Math.ceil get the largest integer not less than a certain number
Math.floor the largest integer less than a certain number
Math.ieeeremainder to seek the remainder
Math.max two number of the largest
Math.min to find the smallest of two numbers
Math.sqrt to seek a prescription
Math.pow the arbitrary order of a number, throws a ArithmeticException handle overflow exception
Math.exp the arbitrary order of E
MATH.LOG10 logarithm with base 10
Math.log Natural logarithm
Math.rint the nearest integer (perhaps larger or smaller than a certain number) from a certain number
Math.Round, return int or long (previous function returns double type)
Math.random returns a random number between 0 and 1.
Usage examples:
Double s=math.sqrt (7);
Double X=math.pow (2,3)//calculates 2 of the 3-time Square
Common methods of math classes in Java