sort only the positive value and remain the negative value with it's index as it is of an array

Try to:

  1. Extract only the positive values
  2. Sort them using Collections.sort (or Array.sort)
  3. Go through the original array and replace the positive values by the ordered ones

In the second loop, for every inputArray[j] you need to find next element which is greater than 0 before comparing.

 public static void main(String[] args) {
        int[] inputArray = {-1, 150, 190, 170, -1, -1, 160, 180};
        int[] outputArray = sortByHeight(inputArray);

        for (int item : outputArray) {
            System.out.print(item + ", ");
        }
    }

    public static int[] sortByHeight(int[] inputArray) {
        for (int i=0; i<inputArray.length; i++) {
            for (int j = 0; j<inputArray.length - 1; j++) {
                int temp = inputArray[j];
                if (temp >= 0) {
                    int k = j+1;
                    while(inputArray[k] < 0)
                       k++;
                    if (inputArray[j] > inputArray[k] && inputArray[k] >= 0) {
                        inputArray[j] = inputArray[k];
                        inputArray[k] = temp;
                    }
                }
            }
        }
        return inputArray;
    }

You could try to sort yourself, or extract just the positive values and sort them, but here is an alternate version that leaves input array unmodified (since returning new array from method would otherwise be unnecessary).

Code simply copies and sorts the input array first, then merges negative values from input array with positive values from sorted array. Since negative values were sorted first, there's no chance of overwriting sorted values being copies.

Code also doesn't box the values, as would otherwise be necessary for building a List<Integer> of positive values.

private static int[] sortByHeight(int[] inputArray) {
    int[] arr = inputArray.clone();
    Arrays.sort(arr);
    int i = 0;
    while (i < arr.length && arr[i] < 0)
        i++;
    for (int j = 0; j < arr.length; j++)
        arr[j] = (inputArray[j] < 0 ? inputArray[j] : arr[i++]);
    return arr;
}

Test

int[] inputArray = {-1, 150, 190, 170, -2, -1, 160, 180};
int[] outputArray = sortByHeight(inputArray);
System.out.println(Arrays.toString(outputArray));

Output

[-1, 150, 160, 170, -2, -1, 180, 190]

The re-use of arr as both the sorted array of all values, and the result array, works because positive value will only be copied down, or stay where they are.

To illustrate:

-1, 150, 190, 170,  -2,  -1, 160, 180   // Input array
 ↓                   ↓    ↓
 ↓                   ↓    ↓
 ↓                   ↓    ↓
-1, 150, 160, 170,  -2,  -1, 180, 190   // Result array
     ↑    ↑    └─────────┐    ↑    ↑
     ↑    └─────────┐    ↑    ↑    ↑
     └─────────┐    ↑    ↑    ↑    ↑
-2,  -1,  -1, 150, 160, 170, 180, 190   // Array after sorting