Задача "Изоморфы наступают"
Мы же по сути сравниваем нулевой элемент со всеми остальными и тут в итоге получается что нулевой это 1 а элемент после -8 это 0 который меньше но почему то его индекс и значение не записываются
public class Solution {
public static void main(String[] args) throws Exception {
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
Pair<Integer, Integer> result = getMinimumAndIndex(data);
System.out.println("The minimum is " + result.x);
System.out.println("The index of the minimum element is " + result.y);
}
public static Pair<Integer, Integer> getMinimumAndIndex(int[] array) {
if (array == null || array.length == 0) {
return new Pair<Integer, Integer>(null, null);
}
//напишите тут ваш код
int indexOfMin = 0;
for (int i = 0; i < array.length; i++)
{
if (array[i] < array[indexOfMin])
{
indexOfMin = i;
}
}
return new Pair<Integer, Integer>(array[indexOfMin], indexOfMin);
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}