Hallo!
Ich beschäftige mich zur Zeit mit Methoden und dazu habe ich folgendes gecodet:
Allerdings dachte ich es käme "Die umgedrehten Werte: 12345", wobei nur die Meldung "Die umgedrehten Werte: " in der Konsole auftaucht. Vielen Dank schonmal im vorraus!
Mfg Silvascus
Ich beschäftige mich zur Zeit mit Methoden und dazu habe ich folgendes gecodet:
Java:
package methoden;
public class SwappedCopy {
public static int[] swappedCopy(int[] copy){
for(int i=0, e=copy.length; i<copy.length;i++,e--){
copy[i]=e;
}
return copy;
}
public static int[] copy(int[] array){
int[] copy = new int[array.length];
for(int i=0; i<array.length;){
copy[i]= array[i];
}
return copy;
}
public static void main(String[] args) {
System.out.println("hey");
int[] array = new int[]{1,2,3,4,5};
System.out.println("Die umgedrehten Werte: ");
for(int i =0;i<swappedCopy(copy(array)).length;i++)
System.out.print(swappedCopy(copy(array))[i]);
}
}
Mfg Silvascus
Zuletzt bearbeitet von einem Moderator: