First, math overview
Provides common mathematical operations and two static constants E (base of natural logarithm) and pi (π)
Second, common methods
package Com.pb.demo1; public class Mathtest { static void main (string[] args) {System . OUT.PRINTLN ( "squared root:" + math.sqrt (9.0 "The maximum value of two:" + Math.max (10,30 "minimum value for two numbers:" + math.min (10,30 2 of 3 times: "+ Math.pow (2,3 rounding: "+ math.round (33.6 System.out.println ("generate a random number between 0-1:" +math.random ()); }}
Random class randomness is a randomly generated class that can specify a range of random numbers that can then be arbitrarily generated in this range.
No. |
Method |
Type |
Describe |
1 |
public boolean Nextboolean () |
Ordinary |
Randomly generate a Boolean value |
2 |
Public double nextdouble () |
Ordinary |
Randomly generated double values |
3 |
public float nextfloat () |
Ordinary |
Randomly generated float values |
4 |
public int Nextint () |
Ordinary |
Randomly generated int values |
5 |
public int Nextint (int n) |
Ordinary |
Randomly generates an int value for a given maximum value |
6 |
Public long Nextlong () |
Ordinary |
Generate a Long value randomly |
Package Com.pb.demo1; Import Java.util.Random; Public class randomtest { publicstaticvoid main (string[] args) { Random Random=new random (); for (int i = 1; I <=10; i++) { System.out.println (Random.nextint (i)); }}}
Java starts from scratch 28 (Math class and Random Class)