The code seems to be working fine, but the verification system is not accepting the solution:
Don't change the main - I haven't
The program must return the correct result - It does
:\
package com.codegym.task.task11.task1123;
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 = 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[] array) {
if (array == null || array.length == 0) {
return new Pair<Integer, Integer>(null, null);
}
//write your code here
for(int i = 0 ; i < array.length-1 ; i++)
{
int k = 0;
for(int j = i ; j < array.length-1 ; j++)
{
if(array[k] > array[k+1])
{
int temp = array[k];
array[k] = array[k+1];
array[k+1] = temp;
}
k++;
}
}
int min = array[0];
int max = array[array.length-1];
return new Pair<Integer, Integer>(min, max);
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}