Codezeile die ich nicht verstehe

Der Scope von d muss noch eins weiter nach außen (und dann als primitive auch initialisiert werden):

Java:
int d = 0;
if (this.w < this.h)
    d = this.w;
else
    d = this.h;

Das Konstrukt heißt übrigens Ternärer Operator:
?: - Wikipedia, the free encyclopedia
 
@turtle: Fast! Eher so:
Java:
int d;
if (this.w < this.h)
    d = this.w;
else
    d = this.h;
Was damit grundsätzlich gemeint ist, war wohl aber schon deinem Code zu entnehmen.

Ark

(Mist, gerade zu spät. 😀)
 
und wenn man sich dann noch an die coding conventions hält:
Java:
int d;
if (this.w < this.h) {
    d = this.w;
}
else {
    d = this.h;
}

edit: @TO: deine Zeile Code beinhaltet einen sogenannten ternären Operator, einfach danach googlen wenn du genaueres wissen willst.
 
Zuletzt bearbeitet:
Hi Archer
Java:
int d = this.w < this.h ? this.w : this.h;
Das ist eine bedingte Zuweisung.

Ich merke mir das so:
Wenn die Bedingung (this.w < this.h) zutrifft dann wird der Ausdruck hinter dem ? angewendet (? this.w), sonst der hinter dem Doppeltunkt: 🙂 this.h).

[TIPP]Wenn TRUE dann ? sonst :[/TIPP]

Findet man auch in C.

Pentalon
 

Zurück
Oben