Не могу понять, почему в методе getMinimumAndIndex цикл для поиска индекса не увеличивает переменную x.
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("Minimum is " + result.x);
System.out.println("Index of 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[] array2 = array;
Arrays.sort(array2);
int y = array2[0];
int x = 0;
for (int t : array){
if(t==y){
break;
}else {
x++;
}
}
//напишите тут ваш код
return new Pair<Integer, Integer>(y, x);
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}
package com.javarush.task.task12.task1233;
import java.util.*;
/*
Изоморфы наступают
*/
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("Minimum is " + result.x);
System.out.println("Index of 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[] array2 = array;
Arrays.sort(array2);
int y = array2[0];
int x = 5;
for (int t : array){
if(t==y){
break;
}else {
x++;
}
}
//напишите тут ваш код
return new Pair<Integer, Integer>(y, x);
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}