A
A
Alexey Anisimov2019-07-30 13:26:20
Java
Alexey Anisimov, 2019-07-30 13:26:20

Why does the compiler see nothing after declaring an array?

public class Sorting {
  static int getMin(int[] array, int first, int last) {
    int min = array[first];

    for (int i = first + 1; i <= last; i++) {
      if (array[i] < min) {
        min = array[i];
      }
    }
    return min;
  }
  static int[] sortBySelect(int[] array) {
    int i = 0;
    int[] result = new int[array.length];

    while (i < array.length) {
      result[i] = getMin(array, i, array.length - 1);
    }

    return result;
  }
  public static void main(String[] args) {
    int[] myArray = new int[] {7, 5, 1, 4, 9, 2, 6, 10, 3, 8};
    int[] newArray = sortBySelect(myArray);
    
    for (int i = 0; i < newArray.length; i++) {
      System.out.println(myArray[i]);
    }

  }
}

after the line int[] newArray = sortBySelect(myArray); the compiler does not see anything and is silent. I don't even understand why the error occurred.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Warlodya, 2019-07-30
@wan340

static int[] sortBySelect(int[] array) {
    int i = 0;
    int[] result = new int[array.length];

    while (i < array.length) {
      result[i] = getMin(array, i, array.length - 1);
    }

    return result;
  }

You have an endless cycle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question