菜鸟问个JAVA问题

2024-12-18 14:53:45
推荐回答(1个)
回答1:

int temp = 0;
int max = 0;
int min = 0;
int maxnum = 0;
int minnum = 0;
max = a[0];
min = a[0];
for (i = 1; i
if (max < a[i]) {
max = a[i];
maxnum = i;
}
if (min > a[i]) {
min = a[i];
minnum = i;
}
}
temp = a[0];
a[0] = a[minnum];
a[minnum] = temp;

temp = a[n - 1];
a[n - 1] = a[maxnum];
a[maxnum] = temp;