Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Array Help

Name: Anonymous 2007-03-07 13:14 ID:dVhKGr1O

I know arrays are easy and everything.. but something which I think should be perfectly logical isn't working in my program.

I'm trying to make a method to reverse the order of my array, so that, for example
1 2 3 4 5
will become
5 4 3 2 1

I use something basic:
int left=array[0];
    int right=array.length;
    while(left<right){
        int temp=array[left];
        array[left]=array[right];
        array[right]=temp;
        left++;
        right--;

But array.length isn't number at the end of the array, it's the size of the array! If I have:

int num[] = new int[10] where num[10]=23, then num.length will return 10, not 23.

So I've tried using something like num[num.length], but I keep getting an error message about something being out of bounds. What am I doing wrong?

In b4 pointless java flames.

Name: Anonymous 2007-03-08 2:40 ID:wEb/pPtP

>>13
reverse = lambda l: l[::-1]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List