16.11.2013 Aufrufe

Programmieren in Java - HostFiXX.de

Programmieren in Java - HostFiXX.de

Programmieren in Java - HostFiXX.de

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

<strong>Programmieren</strong> <strong>in</strong> <strong>Java</strong><br />

1.4.2.6 Die Math-Klasse<br />

Die Math-Klasse enthält nützliche numerische Konstanten und Funktionen:<br />

1. Die Funktionen „m<strong>in</strong>“ und „max“.<br />

2. Der absolute Betrag<br />

3. Zufallszahlen<br />

Die Klasse Math unterstützt die „random“-Metho<strong>de</strong>: public static double random(). Die<br />

„random“-Metho<strong>de</strong> gibt e<strong>in</strong>e Zahl zwischen 0.0 und 1.0 aus.<br />

4. Run<strong>de</strong>n<br />

Run<strong>de</strong>n e<strong>in</strong>er Zahl vom Typ float: public static <strong>in</strong>t round(float a). Gerun<strong>de</strong>t wird auf<br />

die nächste ganze Zahl (z.B. 5.4 auf 5, 5.5. auf 6)<br />

Run<strong>de</strong>n e<strong>in</strong>er Zahl vom Typ double: public static long round(double a)<br />

Abrun<strong>de</strong>n: public static double floor(double a). Math.floor run<strong>de</strong>t immer ab, z.B.<br />

ergibt Math.floor(4.99) die Zahl 4.0.<br />

Aufrun<strong>de</strong>n: public static double ceil(double a). ceil run<strong>de</strong>r immer auf, z.B.:<br />

Math.ceil(4.01) ergibt 5.0.<br />

Run<strong>de</strong>n auf die nächste ganze Zahl: public static double r<strong>in</strong>t(double a).<br />

5. Exponenten und Logarithmen<br />

x<br />

Bestimmen <strong>de</strong>s Expoentialwerts e : public static double exp(double x)<br />

Bestimmen <strong>de</strong>s natürlichen algorithmus ln(x ) : public static double log(double x)<br />

6. Trigonometrische Funktionen<br />

public static double s<strong>in</strong>(double w<strong>in</strong>kel)<br />

public static double cos(double w<strong>in</strong>kel)<br />

Der Wert von w<strong>in</strong>kel wird im Bogenmaß angegeben.<br />

7. Potenzen, Quadratwurzel<br />

y<br />

Bestimmen vom Wert <strong>de</strong>r Potenz x : public static double pow(double x, double y)<br />

Bestimmen <strong>de</strong>r Quadratwurzel von x: public static double sqrt(double x)<br />

8. Mathematische Konstanten<br />

public static f<strong>in</strong>al double E;<br />

public static f<strong>in</strong>al double PI;<br />

117

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!