Java learning-manipulating data using the Math class

Source: Internet
Author: User

Manipulating data using the Math class

The math class is located in the Java.lang package and contains methods for performing basic mathematical operations, all methods of the math class are static methods, so you can use the class name directly when using the methods in that class. Method name, such as: Math.Round ();

Common methods:

Through the case we come to know their use it!!

Operation Result:

The Ps:math class also offers a number of other ways that you can focus on wikis and find out more about them.

Task

Demo

 //defines an integer array with a length of ten    int[] Nums =New int[Ten]; //Assigning a value to an array by looping     for(inti =0; i < nums.length; i++) {        //generates a random number within 10        intx = (int) (Math.random () *Ten); Nums[i]= x;//Assigning a value to an element    }        //using the Foreach loop to output elements in an array     for(intnum:nums) {System. out. print (num +" "); }

Function: Defines an integer array of 10 elements, assigns a value to each element in the array, and outputs the result by randomly generating a random number within 10.

Operating Result: 3 9 6 9 8 4 0 6 3 2

Java learning-manipulating data using the 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.