Jump to content


Check out our Community Blogs

Fischerspooner's Content

There have been 27 items by Fischerspooner (Search limited from 22-October 19)



Sort by                Order  

#322547 Moving elements in an array

Posted by Fischerspooner on 06 December 2006 - 11:48 AM in General Programming

Hi,

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;
     }
}



#322544 New guy in town

Posted by Fischerspooner on 06 December 2006 - 11:36 AM in Introductions

Hello,

Searching the internet about moving elements in an array I bumped on your forum :)
I'm a 29 year old guy getting more and more interested in programming. Just learning Java with BlueJ.
Other hobbies are: getting pierced, tats, music

If you got any questions...fire away:)

-f




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download