Advertisement
Guest User

blabla5

a guest
Oct 30th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public class P4VergleichRatz {
  2.     public static void main(String[] args) {
  3.         int n = 3;
  4.         int i = 3;
  5.  
  6.         while (i < 2 * n) {
  7.             System.out.println("Ausgabe: " + 1.0 / (2 * i + 1));
  8.             i++;
  9.         }
  10.        
  11.         for (i = 4; i <= 2 * n; i++) {
  12.           System.out.println("Ausgabe: " + 1.0 / (2 * i + 1));
  13.         }
  14.        
  15.         /*
  16.         Koennte sofern i >= 2 * n ist ein anderes Ergebnis liefern, da i einmal
  17.         erhoeht wird, auch wenn die Bedingung nicht zutrifft, waehrend dies bei
  18.         den kopfgesteuerten Schleifen nicht der Fall waere. Abfangbar durch
  19.         If-Verzweigung um do-while Schleife mit selber Abbruchbedingung.
  20.         */
  21.         i = 3;
  22.         do {
  23.             System.out.println("Ausgabe: " + 1.0 / (2 * i + 1));
  24.             i++;
  25.         } while (i < 2 * n);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement