# Sorting problem

• 10-23-2006, 04:45 PM
torrinment
Sorting problem
why does this code show the ouput
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9
[I@10b62c9

if you could fix it i wouild appreciate it
Code:

```        public static void swap(int[]a)         {                 int i,n,atemp;                 for(n=1;n<a.length;n++)                 {                         atemp=a[n];                         i=n;                         while(i>0&&atemp<a[i-1])                         {                                 i--;                         }                         a[i]=atemp;                 }         }         public static void main(String[]args)         {                 int[]array={10,7,8,1,3,9,4};                 swap(array);                 for(int i=0;i<array.length;i++)                         System.out.println(array);         }```
• 10-23-2006, 06:15 PM
anubis
ah its because your outputting the hex address (i think thats what its called) and not the actual parts of the array

Code:

`System.out.println(array[i]);`
• 10-23-2006, 06:38 PM
torrinment
that made it show out numbers but its showin 1
7
8
1
3
4
4
do u know whats wrong
• 10-23-2006, 07:19 PM
anubis
uh, well what is it supposed to do? i cant tell whats wrong from just your code.
• 10-23-2006, 09:04 PM
torrinment
its supposed to use insertion sort and sort it from lowest to highest
• 10-24-2006, 08:49 AM
AnghelLeonard
//try this

class test{

public static void insertionSort(int numbers[], int array_size)
{
int i, j, index;

for (i=1; i < array_size; i++)
{
index = numbers[i];
j = i;
while ((j > 0) && (numbers[j-1] > index))
{
numbers[j] = numbers[j-1];
j = j - 1;
}
numbers[j] = index;
}
}

public static void main(String[]args)
{
int[]array={10,7,8,1,3,9,4};
insertionSort(array,array.length);
for(int i=0;i<array.length;i++)
System.out.println(array[i]);
}
}