Почему в моём случае, не смотря на строку 19, изменяется исходный массив?
Потому что я создаю ссылку на тот же объект, верно?
package com.javarush.task.task11.task1123;
public class Solution {
public static void main(String[] args) {
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
Pair<Integer, Integer> result = getMinimumAndMaximum(data);
System.out.println("The minimum is " + result.x);
System.out.println("The maximum is " + result.y);
}
public static Pair<Integer, Integer> getMinimumAndMaximum(int[] inputArray) {
if (inputArray == null || inputArray.length == 0) {
return new Pair<Integer, Integer>(null, null);
}
// напишите тут ваш код
int[] inputArray2 = inputArray;
for(int i = 0; i < inputArray2.length; i++) {
for (int j = i; j < inputArray2.length; j++) {
if (inputArray2[i] > inputArray2[j]) {
int temp = inputArray2[i];
inputArray2[i] = inputArray2[j];
inputArray2[j] = temp;
}
}
}
return new Pair<Integer, Integer>(inputArray2[0], inputArray2[inputArray2.length-1]);
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}