1 / 67

JavaKara programmieren: Daten – Variablen und Methoden mit Parameter und Rückgabewerte

Vom Umgang mit Daten. JavaKara programmieren: Daten – Variablen und Methoden mit Parameter und Rückgabewerte. Kara soll sich eine Zahl merken: Daten speichern in einer Variable. public void myProgram () { int anzahl ; anzahl = tools.intInput ( " Anzahl");

haile
Télécharger la présentation

JavaKara programmieren: Daten – Variablen und Methoden mit Parameter und Rückgabewerte

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Vom Umgang mit Daten JavaKara programmieren:Daten – Variablen und Methoden mit Parameter und Rückgabewerte

  2. Kara soll sich eine Zahl merken: Daten speichern in einer Variable publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); }

  3. Kara soll sich eine Zahl merken: Daten speichern in einer Variable publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } Variable deklarieren Wert speichern Wert auslesen

  4. Kara soll sich eine Zahl merken: Daten speichern in einer Variable publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } Variable deklarieren Wert speichern Wert auslesen Variable deklarieren: Typ (int = Ganzzahl) und Namen definieren Wert speichern: Einen Wert in die Variable schreiben, einen Wert zuweisen; «links vom Gleich» steht die Variable, in die geschrieben werden soll Wert auslesen: Den aktuellen Wert der Variable verwenden, zum Beispiel für Berechnung oder wie oben Ausgabe

  5. Kara soll sich eine Zahl merken: Programmausführung publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } Methode myProgram

  6. Kara soll sich eine Zahl merken: Programmausführung publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } intanzahl = <undefiniert> MethodemyProgram

  7. Kara soll sich eine Zahl merken: Programmausführung publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } intanzahl = 5 MethodemyProgram

  8. Kara soll sich eine Zahl merken: Programmausführung publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } intanzahl = 5 MethodemyProgram

  9. Kara soll sich eine Zahl merken: Programmausführung publicvoidmyProgram() { intanzahl; anzahl= tools.intInput("Anzahl"); tools.showMessage("Anzahl = " + anzahl); } MethodemyProgram

  10. Die grundlegenden («primitiven») Datentypen von Java de.wikibooks.org/wiki/Java_Standard:_Primitive_Datentypen

  11. Kara soll eine Zahl quadrieren publicvoidmyProgram() { intanzahl = tools.intInput("Anzahl?"); intquadratAnzahl = anzahl * anzahl; tools.showMessage( "Quadriert = " + quadratAnzahl ); } Deklaration understen Wert speichernkombiniert

  12. Kara soll eine Zahl quadrieren:Programmausführung publicvoidmyProgram() { intanzahl = tools.intInput("Anzahl?"); intquadratAnzahl = anzahl * anzahl; tools.showMessage( "Quadriert = " + quadratAnzahl ); } MethodemyProgram

  13. Kara soll eine Zahl quadrieren:Programmausführung publicvoidmyProgram() { intanzahl = tools.intInput("Anzahl?"); intquadratAnzahl = anzahl * anzahl; tools.showMessage( "Quadriert = " + quadratAnzahl ); } intanzahl = 9 MethodemyProgram

  14. Kara soll eine Zahl quadrieren:Programmausführung publicvoidmyProgram() { intanzahl = tools.intInput("Anzahl?"); intquadratAnzahl = anzahl * anzahl; tools.showMessage( "Quadriert = " + quadratAnzahl ); } intquadratAnzahl = 81 intanzahl = 9 MethodemyProgram

  15. Kara soll eine Zahl quadrieren:Programmausführung publicvoidmyProgram() { intanzahl = tools.intInput("Anzahl?"); intquadratAnzahl = anzahl * anzahl; tools.showMessage( "Quadriert = " + quadratAnzahl ); } intquadratAnzahl = 81 intanzahl = 9 MethodemyProgram

  16. Kara soll eine Zahl quadrieren:Programmausführung publicvoidmyProgram() { intanzahl = tools.intInput("Anzahl?"); intquadratAnzahl = anzahl * anzahl; tools.showMessage( "Quadriert = " + quadratAnzahl ); } MethodemyProgram

  17. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } // tools.showMessage("i = " + i); geht nicht! kara.putLeaf(); kara.turnRight(); } Gültigkeitsbereich der Variable anzahl Gültigkeitsbereich der Variable i

  18. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("WievieleBlätter?" ); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } MethodemyProgram

  19. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("WievieleBlätter?" ); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram

  20. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 0

  21. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 0

  22. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 0

  23. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 1

  24. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 1

  25. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 2

  26. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram int i = 2

  27. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram

  28. Kara soll Anzahl Kleeblätter legen und auf letztem Blatt eine Rechtsdrehnung machen publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kara.putLeaf(); kara.move(); } kara.putLeaf(); kara.turnRight(); } intanzahl = 3 MethodemyProgram

  29. Erweiterung: Kara soll Kleeblätter nur legen, wenn möglich publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { if (!kara.onLeaf()) { kara.putLeaf(); } kara.move(); } if (!kara.onLeaf()) { kara.putLeaf(); } kara.turnRight(); }

  30. Lesbarkeit erhöhen: Methode einführen für «Kleeblatt legen, wenn möglich» publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); for (int i = 0; i < anzahl-1; i++) { kleeblattFallsMoeglich(); kara.move(); } kleeblattFallsMoeglich(); kara.turnRight(); } voidkleeblattFallsMoeglich() { if (!kara.onLeaf()) { kara.putLeaf(); } }

  31. Erweiterung: Anzahl Kleeblätter legen, bis als Anzahl 0 (oder kleiner) eingegeben wird publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); while (anzahl > 0) { for (int i = 0; i < anzahl-1; i++) { kleeblattFallsMoeglich(); kara.move(); } kleeblattFallsMoeglich(); kara.turnRight(); anzahl = tools.intInput("Wieviele Blätter?"); } } voidkleeblattFallsMoeglich() { if (!kara.onLeaf()) { kara.putLeaf(); } }

  32. Lesbarkeit erhöhen: Eigene Methode für «Kleeblattreihe legen» publicvoidmyProgram() { intanzahl = tools.intInput("Wieviele Blätter?"); while (anzahl > 0) { kleeblattReiheLegen(anzahl); anzahl = tools.intInput("Wieviele Blätter?"); } } voidkleeblattReiheLegen(intn) { for (int i = 0; i < n-1; i++) { kleeblattFallsMoeglich(); kara.move(); } kleeblattFallsMoeglich(); kara.turnRight(); } // kleeblattFallsMoeglichwie oben Aufruf mit Wert Parameter für Wert

  33. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while(anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl= tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(intn) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglichwie oben Methode myProgram

  34. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben intanzahl = 2 Methode myProgram

  35. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben intanzahl = 2 Methode myProgram

  36. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben intanzahl = 2 Methode myProgram

  37. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  38. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int i = 0 int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  39. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int i = 0 int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  40. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int i = 0 int n = 3 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 ___________________________ kleeblattReiheLegen: Zeile 10 ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  41. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int i = 0 int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  42. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int i = 1 int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  43. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  44. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  45. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben int n = 2 Methode kleeblattReiheLegen ___________________________ myProgram: Zeile 04 intanzahl = 3 Methode myProgram

  46. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben intanzahl = 2 Methode myProgram

  47. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben intanzahl = 0 Methode myProgram

  48. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben intanzahl = 0 Methode myProgram

  49. Variablen und Parameter: Programmausführung 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wieviele Blätter?"); 03 while (anzahl > 0) { 04 kleeblattReiheLegen(anzahl); 05 anzahl = tools.intInput("Wieviele Blätter?"); 06 } 06 } 07 08 voidkleeblattReiheLegen(int n) { 09 for (int i = 0; i < n-1; i++) { 10 kleeblattFallsMoeglich(); 11 kara.move(); 12 } 13 kleeblattFallsMoeglich(); 14 kara.turnRight(); 15 } 16 17 // kleeblattFallsMoeglich wie oben Methode myProgram

  50. Kara soll jetzt Kleeblätter zählen: Methoden mit Rückgabewert 01 publicvoidmyProgram() { 02 intanzahl = tools.intInput("Wie weit laufen?"); 03 int gelegt = zaehlen(anzahl); 04 tools.showMessage("Anzahl Blätter: "+gelegt); 05 } 06 07 intzaehlen(int n) { 08 intkleeblaetter = 0; 09 for (int i = 0; i < n; i++) { 10 if (kara.onLeaf()) { 11 kleeblaetter= kleeblaetter + 1; 12 } 13 kara.move(); 14 } 15 returnkleeblaetter; 16 }

More Related