Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.task11;

import java.util.Arrays;
import java.util.NoSuchElementException;

public class Task11Main {
public static void main(String[] args) {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
Expand All @@ -12,7 +15,20 @@ public static void main(String[] args) {
}

static void swap(int[] arr) {
//todo напишите здесь свою корректную реализацию этого метода, вместо существующей
int min;
try {
min = Arrays.stream(arr).min().getAsInt();
} catch (Exception e) {
return;
}
int indexOfMin = lastIndexMin(arr, min);
int swap = arr[0];
arr[indexOfMin] = swap;
arr[0] = min;
}

static int lastIndexMin(int[] arr, int min) throws NoSuchElementException {
for (int i = arr.length - 1; i >= 0; i--) if (arr[i] == min) return i;
throw new NoSuchElementException("The is no element: " + min);
}
}