Results 1 to 2 of 2
  1. #1
    leoshiner is offline Member
    Join Date
    Oct 2010
    Posts
    28
    Rep Power
    0

    Default writing a reverse method

    Hi I'm just trying to write a reverse method which will output array values in reverse and I
    keep getting this output "a in reverse is [I@19821f"


    Here is my code any help would be greatly appreciated:

    public static void main(String[] args) {
    int[]a={2,4,96};



    System.out.print("a in reverse is "+reverse(a));
    }
    public static int[]reverse(int b[]){

    int temp []=new int[b.length];

    for(int i=0,j=temp.length-1;i<b.length;i++,j--){

    temp[j]=b[i];

    }
    return temp;

    }

    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: writing a reverse method

    Yep, you're getting the toString() representation of an int array. If you want to see all the elements of a, you'll have to either use a for loop or use java.util.Arrays.toString(myArray).

Similar Threads

  1. Replies: 8
    Last Post: 07-17-2011, 02:38 PM
  2. Without using reverse method
    By blindfolded916 in forum New To Java
    Replies: 3
    Last Post: 12-08-2010, 06:18 PM
  3. Reverse a string not using the substring method
    By kathyla18 in forum New To Java
    Replies: 17
    Last Post: 04-08-2009, 04:08 AM
  4. how do i reverse this method for sorting?Again!
    By PureAwesomeness in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 12:51 AM
  5. [SOLVED] how do i reverse this method for sorting?
    By PureAwesomeness in forum New To Java
    Replies: 3
    Last Post: 03-08-2009, 09:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •