public class Mathdemo {
public static void Main (string[] args)
{
/**
* Ceil ceiling means to return a large value, note some special values
*/
Double D=math.ceil (16.34); 17.0
Double D=math.ceil (-16.34); -16.0
Double D=math.ceil (1.34); 2.0
/**
* Floor meaning is to return a small value
*/
Double D1=math.floor (12.34); 12.0
Double D1=math.floor (16.34); 16.0
Double D1=math.floor (-16.34); -17.0
/**
* Round rounding, float returns int value, double returns Long value
*/
Long A=math.round (12.34); 12
Long A=math.round (12.54); 13
/**
* MATH.POW (x, y): x y-square
*/
Double D2=math.pow (2, 3); 8
/**
* Math.random Returns a random number between 0 and 1
*/
Double X=math.random (); Returns a random number between 0.0,1.0, greater than or equal to 0.0, less than 1.0
Double x= (int) (Math.random () *10); Returns the number of a random integer between 0.0,10.0
int x= (int) (Math.random () *10+1); Returns a random number between 1,10, which may be 1 or 10
SOP ("d=" +d);
SOP ("d1=" +d1);
SOP ("a=" +a);
SOP ("d2=" +d2);
SOP ("x=" +x);
}
public static void Sop (Object obj)
{
System.out.println (obj);
}
}
Usage of Math