Your code is hardcoded to only work for 5 elements.
What would you have to do to make it work for 8 elements or 50 elements?

then how to make it generic,will int []a=new int[]; work?

06-29-2011, 11:55 PM

Norm

Quote:

to make it generic

To generate an array to sort you'll have to specify its size:
int[] anArray = new int[333];
The code to reverse the array should get anArray as an argument and use the anArray.length property to get its size.

See the Arrays class toString() method as an easy way to print the contents of an array.