Java Learning: Math class

Source: Internet
Author: User

Math: The class used to perform mathematical operations.

Member Methods:
public static int abs (int a)//absolute value
public static double Ceil (double A)//want to go up and take the whole
public static double floor (double A)//down rounding
public static int max (int a,int b)//Take maximum value
public static Double pow (double a,double b)//a B-square
public static double random ()//
public static int round (float a) argument is double for self-study

1                 //public static int abs (int a), take absolute value2System.out.println (Math.Abs (100));3System.out.println (Math.Abs (-100));4         5         //Public static Double Ceil (double A), rounding up6System.out.println (Math.ceil (12.3));7System.out.println (Math.ceil (12.7));8System.out.println (Math.ceil (12.0));9         Ten         //Public static Double floor (double a), rounded down OneSystem.out.println (Math.floor (12.3)); ASystem.out.println (Math.floor (12.7)); -System.out.println (Math.floor (12.0)); -          the         //public static int max (int a,int b) min Self-study -System.out.println (Math.max (2, 3)); -         //determine the maximum value of a 2,3,4 -System.out.println (Math.max (Math.max (2, 3), 4)); +         //If multiple numbers are the maximum value: -         //1. Create an array, store the data in an array, and then use For+if to remove the maximum value +         //2. Bubble sort, remove last value A         //3.arrays.sort (int[] arr), remove the last at          -         //Public static Double pow (double a,double b) A B-square -System.out.println (Math.pow (2, 3)); -          -System.out.println ("---------------"); -          in         //Public static Double random (), resulting in a random number between 0-1, including 0 including 1 - System.out.println (Math.random ()); to         //requirement: Generates a random number between 1-100 +         intRadom = (int) (Math.random () *100+1); - System.out.println (Radom); the          *         //public static int round (float a), rounded $System.out.println (Math.Round (12.4));Panax NotoginsengSystem.out.println (Math.Round (12.6));
Member Method Demo

The results of the operation are as follows:

100
100
13.0
13.0
12.0
12.0
12.0
12.0
3
4
8.0
---------------
0.7210652393976311
75
12
13

Java Learning: Math class

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.