Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class codeverständnis {
- public static void main(String[] args) {
- int a = 1;
- int b = 2;
- boolean c = (a == b); //a!=b => c=false
- System.out.println("\nM" + ausgabe(a, b, c)); //springt in ausgabe() mit parametern 1, 2, false
- //danach ausgabe 21
- System.out.println(a + " ist " + !!c); //ausgabe "1 ist false"
- }
- public static int ausgabe(int x, int y, boolean z) { //wird aufgerufen mit 1, 2, false
- System.out.println("X" + x); // gibt aus "X1"
- if (!z) { //z=false => !z=true=> answeisung wird ausgefuehrt
- System.out.println("\nZ ist " + z); //ausgabe: "Z ist false"
- }
- int a = x; //a = 1
- int b = y + 1; //b=2+1=3
- for (int i = 0; i < 10; i++) {
- int d = i;
- if (d % 2 == 0) {
- System.out.println("D" + d); //Es werden alle geraden zahlen in [0, 9] ausgegeben
- }
- a += 2;
- }
- //a hat den wert 1 + 10*2 = 21
- int d = b; //d darf ausserhalb der schleife nochmal init. werden d=3
- System.out.println("\nEingenwert: " + d + "\n\n"); //ausgabe 3
- int[] f = new int[] { 2, 3, 5, 7, 11, 13, 17 }; //komische syntax, sieht fuer mich nach 'nem fehler aus
- int[] g = new int[f.length]; //g hat 7 felder, Anzahl der Elemente in f
- for (int i = 5; i < f.length + 5; i++) { //Oh mein Gott wie unsinnig umstaendlich!!
- g[i - 5] = f[f.length + 4 - i]; //g ist spiegelverkehrt zu f
- }
- ausgabe2(g); //ausgabe2() mit parameter {17, 13, 11, 7, 5, 3, 2}
- berechnung(g);
- ausgabe2(g); //ausgabe2() mit parameter {1, 2, 3, 4, 5, 6, 7}
- return a; //rueckgabe 21
- }
- public static void berechnung(int[] e) {
- for (int i = 0; i < e.length; i++) {
- e[i] = i; //felder werden mit ihren nummern gefuehlt
- }
- }
- public static void ausgabe2(int[] f) {
- for (int i = 0; i < f.length; i++) {
- System.out.println("WERT: " + f[i]); // Ausgabe der Werte: {17, 13, 11, 7, 5, 3, 2}
- //danach 1, 2, 3, 4, 5, 6, 7
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment