Results 1 to 2 of 2
Thread: writing a reverse method
- 10-10-2011, 10:35 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 28
- Rep Power
- 0
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;
}
}
-
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
-
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 02:38 PM -
Without using reverse method
By blindfolded916 in forum New To JavaReplies: 3Last Post: 12-08-2010, 06:18 PM -
Reverse a string not using the substring method
By kathyla18 in forum New To JavaReplies: 17Last Post: 04-08-2009, 04:08 AM -
how do i reverse this method for sorting?Again!
By PureAwesomeness in forum New To JavaReplies: 2Last Post: 03-09-2009, 12:51 AM -
[SOLVED] how do i reverse this method for sorting?
By PureAwesomeness in forum New To JavaReplies: 3Last Post: 03-08-2009, 09:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks