17
java Math Class java.lang.Math

Math Class

Embed Size (px)

DESCRIPTION

this is about math class that we can use in the the java language

Citation preview

Page 1: Math Class

javaMath Class

java.lang.Math

Page 2: Math Class

Math Class

أهميه • ذات ضخمة مكتبة على تحتوي الجافا لغةكبيره وفاعلية

المكتبة • هذه محتويات Math Classمنال • مكتبة استيراد إلى نحتاج لغة Mathال في كما

السيالحسابية Math Classتحتوي • العمليات من العديد على

مسبقا المعرفةالدوال • هذه أكثر على المقرر هذا في نركز سوف

استخداما.

Page 3: Math Class

Math Class

double Math.E() Value of e, 2.718282..., base of the natural logarithms.

double Math.PI() Value of pi, 3.14159265 ....

Math.abs(x) Returns absolute value of x.

Page 4: Math Class

public class MathClass { public static void main(String[] args) { System.out.println("e = " + (Math.E));

System.out.println("pi = " + (Math.PI));

System.out.println();

System.out.println("Absolute number = " + Math.abs(-4)); System.out.println("Absolute number = " + Math.abs(4)); System.out.println("Absolute number = " + Math.abs(-4.44)); }}

Page 5: Math Class

The output

e = 2.718281828459045pi = 3.141592653589793

Absolute number = 4Absolute number = 4Absolute number = 4.44

Page 6: Math Class

Math Class

Math.pow(d1, d2) Returns d1d2.

Math.sqrt(d) Returns the square root of d.

Math.random() Returns a number x in the range, 0.0 <= x < 1.0. This creates a random number between the values of 0.0 and 1.0.

Page 7: Math Class

public class MathClass { public static void main(String[] args) { System.out.println("Power = " + Math.pow(10,3)); System.out.println();

System.out.println("Random Number = " + Math.random()); System.out.println("Random Number 0-50 = " +(int)(Math.random()*50)); System.out.println(); System.out.println("Square Root = " + Math.sqrt(25)); System.out.println("Square Root = " +(int)Math.sqrt(25)); } }

Page 8: Math Class

The outputPower = 1000.0

Random Number = 0.5178556008893547Random Number 0-50 = 20

Square Root = 5.0Square Root = 5

Page 9: Math Class

Math Class

Math.IEEERemainder(x,y) Returns the remainder result

from the division of X by Y which is equivalent to x%y

Math.max(x, y) Returns maximum of x and y.

Math.min(x, y) Returns minimum of x and y

Page 10: Math Class

public class MathClass { public static void main(String[] args) { System.out.println("Remainder = " + Math.IEEEremainder(5,2)); System.out.println("Remainder = " + Math.IEEEremainder(6,2)); System.out.println();

System.out.println("Maximum Number = " + Math.max(10,10.3)); System.out.println("Maximum Number = " + Math.max((Math.max(10,10.3)),(55))); System.out.println(); System.out.println("Minimum Number = " + Math.min(10,10.3)); System.out.println("Minimum Number = " + Math.min((Math.min(10,10.3)),(55))); }}

Page 11: Math Class

The outputRemainder = 1.0Remainder = 0.0

Maximum Number = 10.3Maximum Number = 55.0

Minimum Number = 10.0Minimum Number = 10.0

Page 12: Math Class

Math Class

Math.floor(d) Returns the closest integer-valued which is equal to

or less than d.

Math.ceil(d) Returns the closest integer-valued double which is

equal to or greater than d.

Page 13: Math Class

public class MathClass { public static void main(String[] args) { System.out.println("ceil(3.33) = " + Math.ceil(3.33)); System.out.println("ceil(3.99) = " + Math.ceil(3.99)); System.out.println("ceil(-3.33) = " + Math.ceil(-3.33)); System.out.println("ceil(-3.99) = " + Math.ceil(-3.99)); System.out.println(); System.out.println("floor(3.33) = " + Math.floor(3.33)); System.out.println("floor(3.99) = " + Math.floor(3.99)); System.out.println("floor(-3.33) = " + Math.floor(-3.33)); System.out.println("floor(-3.99) = " + Math.floor(-3.99)); }}

Page 14: Math Class

The outputceil(3.33) = 4.0ceil(3.99) = 4.0ceil(-3.33) = -3.0ceil(-3.99) = -3.0

floor(3.33) = 3.0floor(3.99) = 3.0floor(-3.33) = -4.0floor(-3.99) = -4.0

Page 15: Math Class

Math Class

Math.round(f) Returns the int which is closest in value to the float f.

Page 16: Math Class

public class MathClass { public static void main(String[] args) { System.out.println("round 5.8 = " + Math.round(5.8)); System.out.println("round 5.6 = " + Math.round(5.6)); System.out.println("round 5.5 = " + Math.round(5.5)); System.out.println("round 5.4 = " + Math.round(5.4)); System.out.println("round 5.3 = " + Math.round(5.3)); System.out.println(); System.out.println("round -5.8 = " + Math.round(-5.8)); System.out.println("round -5.6 = " + Math.round(-5.6)); System.out.println("round -5.5 = " + Math.round(-5.5)); System.out.println("round -5.4 = " + Math.round(-5.4)); System.out.println("round -5.3 = " + Math.round(-5.3)); } }

Page 17: Math Class

The outputround 5.8 = 6round 5.6 = 6round 5.5 = 6round 5.4 = 5round 5.3 = 5

round -5.8 = -6round -5.6 = -6round -5.5 = -5round -5.4 = -5round -5.3 = -5