i've been trying to get this array to reverse then print the reverse. well i do believe i have my logic right and everytime i compile it works fine, then when i run it gives me an error, this code is in java format, if anyone could help me or tell me what i'm doing wrong that would be great.
my code is: public class reverseArrayTwo {
public static void main(String[] args) { String[] forwardArray ={"one", "two", "three", "four", "five", "six"}; String[] backwardArray =new String [6]; int forwardIndex = 0; for (int i = 0; i < forwardArray.length; i++) { backwardArray[forwardArray.length - i] = forwardArray; }
i'm not that much good in programming but i think u need to store the elements in temp variable and reverse also, i think u need to print the array befor reversing then do the reversem and finaly print the reverse
publicclass reverseArrayTwo
{
String[] backwardArray =new String [6];
int forwardIndex = 0;
for (int i = 0; i < forwardArray.length; i++)
{
// The first time in the loop this will give an Array Out
of bounds.
i.e. first time i = 0. Length - 0 is index [6] remember Arrays work from Index 0 meaning an Array of size 6 will have indeces up to 5. i.e. ArrayOutOfBoundsException.
Maybe rework your logic to factor this in.
backwardArray[forwardArray.length - i] =
] = forwardArray[i];
}
System.out.print(forwardArray);
System.out.print(backwardArray);
}
> }