q738...@yahoo.com.tw
unread,Dec 24, 2010, 9:43:22 AM12/24/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to EnJoyJava
public class example {
public static void main(String[] args) {
int ary[] = {1,2,3,4,5,6};
for (int i : ary) {
System.out.print(i+",");
}
reverse(ary,0,ary.length-1);
System.out.println();
for (int i : ary) {
System.out.print(i+",");
}
}
public static int[] reverse (int[] ary, int left , int right) {
if (right > ary.length/2-1) {
int tmp = ary[left];
ary[left] = ary[right];
ary[right] = tmp;
return reverse(ary,left+1,right-1);
}
return ary;
}
}