Usage of Math

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.