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
  • 781
  • 2
  • 14
  • 25
ChawBawwa
  • 43
  • 1
  • 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
  • 334,321
  • 69
  • 703
  • 674
  • 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,800
  • 3
  • 38
  • 61
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
  • 65,990
  • 13
  • 130
  • 167