Advertisement
FichteFoll

Informatik 10 / - Schriftliche Übung 3 | Aufgabe 4

Feb 8th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. /// Informatik 10 / Programmieren mit Java - Schriftliche Übung Nr. 3 (01.04.11)
  2.  
  3. /* 4. Der Aufruf der Methode `wuerfelergebnis` soll eine ganze Zufallszahl aus dem Bereich von 1 bis 6 zurückliefern.
  4.  *    Die folgende Methodendefinition weist etliche Fehler auf.
  5.  *    Schreibe diese Methode fehlerfrei.
  6.  */
  7.  
  8. public Int wuerfelergebnis{
  9.   Double Zufallszahl;
  10.   Zufallszahl = math.Random();
  11.   Zufallszahl = math.floor(Zufallszahl*6);
  12.   Zufallszahl = Zufallszahl+1;
  13.   Return (Zufallszahl);
  14.  
  15. /* "Musterlösung": */
  16.  
  17. public void int wurfelergebnis(){
  18.   double Zufallszahl;
  19.   Zufallszahl=Math.random();
  20.   Zufallszahl=Math.floor(Zufallszahl*6);
  21.   Zufallszahl = Zufallszahl+1;
  22.   return (int) Zufallszahl;
  23. }
  24.  
  25. /* Meine Lösung: */
  26.  
  27. public int wuerfelergebnis()
  28.   return (int) (Math.random()*6 + 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement