You just need to work through this formula to see if it is correct:
return (sort[(sort.length / 2) - 1] + sort[(sort.length) / 2] / 2)
So, for an even number of elements in the array, say '6',...
Type: Posts; User: GregBrannon
You just need to work through this formula to see if it is correct:
return (sort[(sort.length / 2) - 1] + sort[(sort.length) / 2] / 2)
So, for an even number of elements in the array, say '6',...
The error, "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at media.main(media.java:44)" points at this code:
/* Sorting begins */
for ( i = 1 ; i <= n-1...
Wait to define the a[] array until you know how many elements it should have. Something like:
System.out.println("Enter the number of items\n");
try {
...