0

Here is my code. Can someone help me with this error?

public class ExcahngeSort {

    public double[] ExSort(double[] gangnam,int size)
    { double temp;

        for(int outrloop=1;outrloop<size;outrloop++)
        {

            for (int innrloop=0;innrloop<size-outrloop;innrloop++)
            {

                if(gangnam[innrloop]>gangnam[innrloop+1])
                {
                     temp=gangnam[innrloop];
                    gangnam[innrloop]=gangnam[innrloop+1];
                    gangnam[innrloop+1]=temp;
                }
            }
        }   
        return gangnam;
    }
}

I get an unexpected value [D@360be0printed. I don't know what this means.

Here is my main method:

public class BsortSimulate {
    public static void main (String args []){

        //BSort bs = new BSort();
        ExcahngeSort es = new ExcahngeSort();
        double gangnam [] = {12,24};

        System.out.println(es.ExSort(gangnam, 2));

        }
}
hat
  • 733
  • 1
  • 17
  • 23
ChawBawwa
  • 33
  • 5

3 Answers3

2

You are printing the array incorrectly, use Arrays.toString() utility method:

System.out.println(Arrays.toString(es.ExSort(gangnam, 2)));

Arrays in Java do not override toString(), as opposed to most List implementations.

Tomasz Nurkiewicz
  • 324,247
  • 67
  • 682
  • 662
  • but when i make the change as u said i dont get any output .i import the import java.util.Arrays; package also and im a newbie please help me with this. i think it must be an error in my code not in the array – ChawBawwa Oct 17 '12 at 18:10
1
System.out.println(Arrays.toString(es.ExSort(gangnam, 2)));
banjara
  • 3,658
  • 3
  • 35
  • 55
0

It is not an error. You are trying to print array object. You can't override toString() for arrays in Java.

Your print statement should be like below:

Example:

System.out.println(Arrays.toString(es.ExSort(gangnam, 2)));
kosa
  • 64,776
  • 13
  • 121
  • 163