Math class:
The math class is A class for mathematical calculations under the Java.lang package. The Math class contains methods for performing basic mathematical operations, such as elementary exponents, logarithms, square roots, and trigonometric functions .
Some methods of the math class:
Math.random ();
Get random values for floating-point types
Math.PI ();
Get pi
Math.Abs ();
Get absolute value
Math.Round ();
Rounded
Math.floor ();
to return a double value that is less than or equal to the argument and equals an integer
Math.max ();
Get the maximum value from two values
Math.min ();
Get the smallest of two values
Math.nextdown (double D);
returns a little bit more floating point than D
Math.nextup (double D);
return D and the positive infinity between D adjacent floating-point values
MATH.SQRT (double D);
Gets the square root of the double value that is rounded correctly
code example:
650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/26/4de1d9cd555e436b436b6259c85ccc04.png "style=" float: none; "title=" vip14-end bowl blowing water -4.14-math class and Arrays class 450.png "alt=" 4de1d9cd555e436b436b6259c85ccc04.png "/>
Operation Result:
650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/26/0bd98c628de52f43f5a20aa010cbf1b4.png "title=" vip14-End Bowl blowing water -4.14-math class and Arrays class 460.png "alt=" 0bd98c628de52f43f5a20aa010cbf1b4.png "/>
Random class:
random number class, this class uses the seed of the decimal place. Different types of random values can be obtained using the method. You can customize the range of random values.
Common methods:
Nextint (500);
get a random int value less than
Nextint ();
get a random int value
Nextfloat ();
get a random float value of 1 or less
Nextdaoble ();
get a random double value of 1 or less
Nextdaoble () *100;
get a random double value within
Nextbytes (byte[] b);
generates a random byte and places it in a user-supplied byte array. The number of random bytes generated equals the length of the byte array.
code example:
650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/26/ac377d4769179ee92a5de97186f5224f.png "style=" float: none; "title=" vip14-end bowl blowing water -4.14-math class and Arrays class 753.png "alt=" Ac377d4769179ee92a5de97186f5224f.png "/>
Operation Result:
650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/26/399f00f095e6ba2560830cd43c68ceaf.png "title=" vip14-End Bowl blowing water -4.14-math class and Arrays class 764.png "alt=" 399f00f095e6ba2560830cd43c68ceaf.png "/>
Array collection:
The collection of arrays is equivalent to an infinitely growing container that can hold various types, and this container provides methods for adding, modifying, deleting, obtaining, and so on.
How to add a collection of arrays:
the way to add an array collection is to first request a An object array, which is used to store the data types passed in, with object as an array in order to accommodate different types. The application of the index attribute is used to record and control the subscript in an array.
method, declare a Object parameter type to receive the passed in parameters, enter the method after the first to determine Whether the object array is null, is the first time to add, create a new length an Object array of ten , which is the initial value of this set.
Add the second or more to enter the Else section, after entering the else to determine Whether the length of the Object array is equal to index+1 , this sentence is used to determine whether to expand the array, if you do not need to expand the parameters passed in into the Object array in the position of the subscript plus one.
If you need to expand, apply a length of The object array length is multiplied by the new object array of 1.6, and then the object is used in the memory copy method Copy the array to the new array, and then Change the reference of the object array to the new array object. This achieves the effect of infinite array growth, but because not every time the need to expand, and in the expansion of the use of memory copy method, so very fast, and not so expensive resources, the less the number of expansion to run faster.
code example:
650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/26/2c729177a03372629922f4e6254c0b1e.png "style=" float: none; "title=" vip14-end bowl blowing water -4.14-math class and Arrays class 1343.png "alt=" 2c729177a03372629922f4e6254c0b1e.png "/>
Test run Speed:
650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/26/18aec8604d9b2ab4e6cd0bfdf700f3d6.png "style=" float: none; "title=" vip14-end bowl blowing water -4.14-math class and Arrays class 1355.png "alt=" 18aec8604d9b2ab4e6cd0bfdf700f3d6.png "/>
Operation Result:
650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/26/2ec6192308e6a9f069af82b8d8f3a3a2.png "style=" float: none; "title=" vip14-end bowl blowing water -4.14-math class and Arrays class 1363.png "alt=" 2ec6192308e6a9f069af82b8d8f3a3a2.png "/>
This article is from the "zero" blog, make sure to keep this source http://zero01.blog.51cto.com/12831981/1976509
Math class, Random class, and array collection