Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class P4VergleichRatz {
- public static void main(String[] args) {
- int n = 3;
- int i = 3;
- while (i < 2 * n) {
- System.out.println("Ausgabe: " + 1.0 / (2 * i + 1));
- i++;
- }
- for (i = 3; i < 2 * n; i++) {
- System.out.println("Ausgabe: " + 1.0 / (2 * i + 1));
- }
- /*
- Koennte sofern i >= 2 * n ist ein anderes Ergebnis liefern, da i einmal
- erhoeht wird, auch wenn die Bedingung nicht zutrifft, waehrend dies bei
- den kopfgesteuerten Schleifen nicht der Fall waere. Abfangbar durch
- If-Verzweigung um do-while Schleife mit selber Abbruchbedingung.
- */
- i = 3;
- do {
- System.out.println("Ausgabe: " + 1.0 / (2 * i + 1));
- i++;
- } while (i < 2 * n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement