public static void main(String[] args) {
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
numbers = Arrays.stream(numbers).map(num -> num*2);
replace(numbers);
Arrays.stream(numbers).forEach(System.out::println);
}
public static void replace(int[] massive) {
int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, mx = 0, mn = 0;
for(int i = 0; i < massive.length; i++) {
if(massive[i] > max) {
max = massive[i];
mx = i;
if(massive[i] < min) {
min = massive[i];
mn = i;
massive[mn] = max;
massive[mx] = min;
return massive;
public static void main(String[] args) {
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
numbers = Arrays.stream(numbers).map(num -> num*2);
replace(numbers);
Arrays.stream(numbers).forEach(System.out::println);
}
public static void replace(int[] massive) {
int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE, mx = 0, mn = 0;
for(int i = 0; i < massive.length; i++) {
if(massive[i] > max) {
max = massive[i];
mx = i;
}
if(massive[i] < min) {
min = massive[i];
mn = i;
}
}
massive[mn] = max;
massive[mx] = min;
return massive;
}