mercredi 30 novembre 2016

[Verständnisproblem] Array wird trotz void rückgabe verändert.

mercredi 30 novembre 2016
Hey Leute,
Ich habe eine Frage bezüglich folgenden Codes:

public class Main {
public static void main(String[] args){
int[] gramm = {1,1,1,1};
Berechnung test = new Berechnung();

test.grammVeränderung(gramm);

System.out.println(gramm[0]);
}
}

public class Berechnung {
public void grammVeränderung(int[] gramm){

for(int i = 0; i<4; i++){
gramm = 2;
}

}
}

Ergebnis: 2

Wieso lässt sich das Array gramm...


[Verständnisproblem] Array wird trotz void rückgabe verändert.

[Verständnisproblem] Array wird trotz void rückgabe verändert.

0 commentaires:

Enregistrer un commentaire

 
◄Design by Pocket