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