I'm currently studying Java on my own and I wanted to try to "rotate" elements in an array.
So the start would be:
{5,3,8,7,7,2,0,6,1,4}
But if I enter "rotate 1" it should give me
{4,5,3,8,7,7,2,0,6,1}
But I keep running into ArrayIndexOutOfBounds errors if I check my pseudocode in Java.
I don't want some code, just a hint or two would be very much appreciated:)
This is what I have already:
for(t=DIM-1 ; t > rot ; t--)
{
if(t < DIM)
{
k = table[t];
table[t-1] = table[t];
table[t+1]= k;
}
else
{
k = table[t];
table[t-1] = table[t-DIM];
table[t+1] = k;
}
}


Sign In
Create Account


Back to top









