LukasHuhn

Laurenz Codeverstaendniss

Jan 7th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. public class codeverständnis {
  2.     public static void main(String[] args) {
  3.         int a = 1;
  4.         int b = 2;
  5.         boolean c = (a == b);               //a!=b => c=false
  6.         System.out.println("\nM" + ausgabe(a, b, c));   //springt in ausgabe() mit parametern 1, 2, false
  7.                                 //danach ausgabe 21
  8.         System.out.println(a + " ist " + !!c);      //ausgabe "1 ist false"
  9.     }
  10.  
  11.     public static int ausgabe(int x, int y, boolean z) {    //wird aufgerufen mit 1, 2, false
  12.         System.out.println("X" + x);            // gibt aus "X1"
  13.         if (!z) {                   //z=false => !z=true=> answeisung wird ausgefuehrt
  14.             System.out.println("\nZ ist " + z); //ausgabe: "Z ist false"
  15.         }
  16.         int a = x;                  //a = 1
  17.  
  18.         int b = y + 1;                  //b=2+1=3
  19.         for (int i = 0; i < 10; i++) {
  20.             int d = i;             
  21.             if (d % 2 == 0) {
  22.                 System.out.println("D" + d);    //Es werden alle geraden zahlen in [0, 9] ausgegeben
  23.             }
  24.             a += 2;
  25.         }
  26.                                 //a hat den wert 1 + 10*2 = 21
  27.         int d = b;              //d darf ausserhalb der schleife nochmal init. werden d=3
  28.         System.out.println("\nEingenwert: " + d + "\n\n");  //ausgabe 3
  29.         int[] f = new int[] { 2, 3, 5, 7, 11, 13, 17 };  //komische syntax, sieht fuer mich nach 'nem fehler aus
  30.         int[] g = new int[f.length];             //g hat 7 felder, Anzahl der Elemente in f
  31.         for (int i = 5; i < f.length + 5; i++) {    //Oh mein Gott wie unsinnig umstaendlich!!
  32.             g[i - 5] = f[f.length + 4 - i];     //g ist spiegelverkehrt zu f
  33.         }
  34.         ausgabe2(g);                    //ausgabe2() mit parameter {17, 13, 11, 7, 5, 3, 2}
  35.         berechnung(g);                 
  36.         ausgabe2(g);                    //ausgabe2() mit parameter {1, 2, 3, 4, 5, 6, 7}
  37.         return a;                   //rueckgabe 21
  38.     }
  39.  
  40.     public static void berechnung(int[] e) {
  41.         for (int i = 0; i < e.length; i++) {
  42.             e[i] = i;           //felder werden mit ihren nummern gefuehlt
  43.         }
  44.     }
  45.  
  46.     public static void ausgabe2(int[] f) {
  47.         for (int i = 0; i < f.length; i++) {
  48.             System.out.println("WERT: " + f[i]);    // Ausgabe der Werte: {17, 13, 11, 7, 5, 3, 2}
  49.                                 //danach 1, 2, 3, 4, 5, 6, 7
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment