0

Why do i only get the location and not the result when i call the method? I thought I did everything right but seems like I didn't, since the output is: [I@f6f4d33

public class ExtremaElements {

    public static int[] computeMinMax(int[] a) {
        if(a.length == 0){
            throw new IllegalArgumentException();
        }
        if(a.length == 1){
           return new int[] {a[0], a[0]};
        }
        int min = a[0];
        int max = a[1];
        if(min > max){
            min = a[1];
            max = a[0];
        }
        for(int i = 2; i < a.length; i++){
            if(a[i] < min){
                min = a[i];
            } else if(a[i] > max){
                max = a[i];
            }
            return new int[] {min, max};

        }
        return new int[] {min, max};
    }
    public static void main (String[]args){
        ExtremaElements bob = new ExtremaElements();
        int[] array = {7, 9, 10, 2, 23, 17, 15};

        System.out.println(bob.computeMinMax(array));
    }
}

I was expecting the result to be: 2, 23

Pshemo
  • 122,468
  • 25
  • 185
  • 269

0 Answers0