Arrays in Java Teil2
04. Februar 2009 Feedback schreibenpublic class referenz {
public static void main(String[] args){
int [] feld1 = new int[2];
int [] feld2 = new int[2];
feld1[0] = 1;
feld1[1] = 11;
feld2[0] = 2;
feld2[1] = 12;
//drucke(feld1);
//tausch1(feld1, feld2);
tausch2(feld1, feld2);
}
public static void drucke(int [] feld){
for(int i=0; i < feld.length; i++){
System.out.print(feld[i] +(” “));
}
}
public static void tausch1(int [] feld1, int [] feld2){
int[] tmp;
tmp = feld1;
feld1 = feld2;
feld2 = tmp;
drucke(feld1);
drucke(feld2);
}
public static void tausch2(int [] feld1, int [] feld2){
int y;
int x;
y = feld1[0];
x = feld1[1];
feld1[0] = feld2[0];
feld1[1] = feld2[1];
feld2[0] = y;
feld2[1] = x;
drucke(feld1);
drucke(feld2);
}
}