So I got a little question again about array swapping.
So I got this little piece of code here:
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random random = new Random();
int indexe = scan.nextInt();
System.out.println("Ihre Indexauswahl: " + indexe);
int[] array = new int[indexe];
System.out.println("Array:");
System.out.println("{");
for (int i = 0; i < array.length; i++) {
array[i] = 1 + random.nextInt(99);
System.out.println(i + " => " + array[i]);
}
System.out.println("}\nArray:\n{");
for (int i = 0; i < array.length / 2; i++) {
int temp = array[i];
array[i] = array[array.length - i - 1];
array[array.length - i - 1] = temp;
System.out.println(i + " => " + array[i]);
}
System.out.println("}");
}
I tested the swapping from my array and If I have 10 indexes in my array, and swap it, then only 5 indexes show up in the System.out.print.
If I remove the " /2 " in the for condition then I get 10 indexes but wrong values in the last 5.
How can I fix this?
Picture with the "/2":
Picture without the "/2":