class Day05_Work3 {
public static void main(String[] args) {
int[] arr = {6,2,9,15,1,5,20,7,18};
int a = getMax(arr);
int b = getMin(arr);
System.out.println(a);
System.out.println(b);
array(arr,a,b);
}
public static int getMax(int[] arr) {
int temp = arr[0];
for (int a = 1;a < arr.length ;a++ ) {
if (temp <= arr[a] ) {
temp = arr[a];
}
}
int sum1 = 0;
for (int b =0;b < arr.length ;b++ ) {
if (arr[b] == temp) {
break;
}
sum1++;
}
return sum1;
}
public static int getMin(int[] arr) {
int temp = arr[0];
for (int a = 1;a < arr.length ;a++ ) {
if (temp >= arr[a] ) {
temp = arr[a];
}
}
int sum1 = 0;
for (int b =0;b < arr.length ;b++ ) {
if (arr[b] == temp) {
break;
}
sum1++;
}
return sum1;
}
public static void array(int[]arr ,int a, int b) {
int temp = 0;
temp = arr[0];
arr[0] = arr[b];
arr[b] = temp;
int temp1 = 0;
temp1 = arr[arr.length-1];
arr[arr.length - 1] = arr[a];
arr[a] = temp1;
for (int c = 0;c < arr.length ;c++ ) {
System.out.print(arr[c]+ " ");
}
}
}
|
|