My Code:
public static int invertieren(int[] werte) {
int[] werte1 = new int[werte.length];
for (int i = 0; i < werte.length; i++) {
for (int j = werte.length - 1; i < j; j--) {
werte1[j] = werte[i];
}
}
return werte1[0];
}
This is my code, I developed a Method that should reverse my Array. for example: in the main Method:
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1,2,3,4,7,5};
System.out.println(invertieren(a));
}
and I need the that in position 0 - werte1[0]
should give me 5
back.
werte1[0] = 5
werte1[1] = 7
werte1[2] = 4
my new Array should look like that: int[] werte = {5,7,4,3,2,1}
my quastion I have not been answered before, cause I'm asking about my code, to learn from making it right.