Upload
abdullah-alghamdi
View
214
Download
1
Embed Size (px)
DESCRIPTION
this is about math class that we can use in the the java language
Citation preview
javaMath Class
java.lang.Math
Math Class
أهميه • ذات ضخمة مكتبة على تحتوي الجافا لغةكبيره وفاعلية
المكتبة • هذه محتويات Math Classمنال • مكتبة استيراد إلى نحتاج لغة Mathال في كما
السيالحسابية 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.
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)); }}
The output
e = 2.718281828459045pi = 3.141592653589793
Absolute number = 4Absolute number = 4Absolute number = 4.44
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.
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)); } }
The outputPower = 1000.0
Random Number = 0.5178556008893547Random Number 0-50 = 20
Square Root = 5.0Square Root = 5
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
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))); }}
The outputRemainder = 1.0Remainder = 0.0
Maximum Number = 10.3Maximum Number = 55.0
Minimum Number = 10.0Minimum Number = 10.0
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.
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)); }}
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
Math Class
Math.round(f) Returns the int which is closest in value to the float f.
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)); } }
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