Back to Browse

2.10 Unit 2 Summary | CSAwesome APCSA Java

439 views
Apr 13, 2022
9:25

#apcsa #learnjava Static Math methods can be called using Math.method(); for each method. The following static Math methods are part of the Java Quick Reference: int abs(int) : Returns the absolute value of an int value (which means no negatives). double abs(double) : Returns the absolute value of a double value. double pow(double, double) : Returns the value of the first parameter raised to the power of the second parameter. double sqrt(double) : Returns the positive square root of a double value. double random() : Returns a double value greater than or equal to 0.0 and less than 1.0 (not including 1.0)! The values returned from Math.random can be manipulated to produce a random int or double in a defined range. (int)(Math.random()*range) + min moves the random number into a range starting from a minimum number. The range is the (max number - min number + 1). For example, to get a number in the range of 5 to 10, use the range 10-5+1 = 6 and the min number 5: (int)(Math.random()*6) + 5.

Download

0 formats

No download links available.

2.10 Unit 2 Summary | CSAwesome APCSA Java | NatokHD