Java.lang.Math: One of the most important Java tools classes, providing many common mathematical methods.
code example :
Public classTest { Public Static voidMain (string[] args) {DoubleA = 10.5; Doubleb =-10.5; //ABS: Take absolute valueSystem.out.println (A + "absolute value:" +Math.Abs (a)); System.out.println (b+ "Absolute value:" +Math.Abs (b)); System.out.println ("--------------------"); //ceil: Takes the smallest integer larger than the passed-in parameter (double type)System.out.println (A + "larger minimum integer:" +Math.ceil (a)); System.out.println (b+ "Larger minimum integer:" +Math.ceil (b)); System.out.println ("--------------------"); //Floor : Takes the largest integer (double type) smaller than the incoming parameterSystem.out.println (A + "smaller maximum integer:" +Math.floor (a)); System.out.println (b+ "Smaller maximum integer:" +Math.floor (b)); System.out.println ("--------------------"); //random number between random:0-1 (double type)System.out.println ("Random number between 0-1:" +math.random ()); System.out.println ("Random number between 0-1:" +math.random ()); System.out.println ("--------------------"); //rint: Rounding (even if *.5)System.out.println ("Rint Rounding:" +Math.rint (a)); System.out.println ("Rint Rounding:" +Math.rint (b)); System.out.println ("Rint Rounding:" +math.rint (10.1)); System.out.println ("Rint Rounding:" +math.rint (10.7)); System.out.println ("--------------------"); //Round: Rounding (float returns int,double return long)System.out.println ("Round rounding:" +Math.Round (a)); System.out.println ("Round rounding:" +Math.Round (b)); System.out.println ("Round Rounding:" +math.round (10.1)); System.out.println ("Round Rounding:" +math.round (10.7)); System.out.println ("--------------------"); //Max: Take a larger number min: Go to a smaller numberSystem.out.println ("Larger number:" +Math.max (A, b)); System.out.println ("Smaller number:" +Math.min (A, b)); System.out.println ("--------------------"); }} Output:Absolute value of 10.5: The absolute value of 10.5-10.5:10.5--------------------10.5 The largest smallest integer: 11.0-10.5 The larger smallest integer: -10.0--------------------10.5 Smaller maximum integer: 10.0-10 .5 Small Maximum integer: -11.0--------------------0-1 random number: 0.33381578000626720-1:0.3831866162450892------------------- -rint Rounding:10.0rint Rounding:-10.0rint Rounding:10.0rint Rounding:11.0--------------------Round rounding:11Round rounding:-10Round rounding:10Round rounding:--------------------larger number:10.5smaller number:-10.5--------------------
Tool class: Math