The error is an ArrayIndexOutOfBoundsException
which I understand yet I don't know where the error is on the code.
public class Main {
public static void main(String[] args) {
double[] testArray = new double[]{3.5, 7.9, 0.0, -7.9, 10.99, 78.9, 66.8, 19.01, 18.9,99.7}; //declaring desired array
double[] reversedTArray = new double[10]; // Using variable to reverse the first array
for (double i = 1; i < testArray.length;i++ ){
reversedTArray[1-(int)i] = testArray[10-(int)i];
}
for (double i : reversedTArray){
System.out.println(reversedTArray[(int)i]);
}
}
}
I'm simply attempting to reverse an array by assigning the reversed one to a new array using a for loop.I expected the values to reverse but it just showed me an error.
The result I want would be this:
99.7
18.9
19.01
66.8
78.9
10.99
-7.9
1.0
7.9
3.5