解题思路:
注意事项:
参考代码:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
Scanner in = new Scanner(System.in);
for (int a = 0; a < 10; a++) {
list.add(in.nextInt());
}
int m = list.get(0);
int locate = 0;
//找到最小值
for(int a = 1;a < 10;a ++){
if(m>list.get(a)){
m=list.get(a);
locate=a;
}
}
//交换
int tem;
tem = list.get(0);
list.set(0, m);
list.set(locate, tem);
//找到最大值
m = list.get(0);
locate = 0;
for(int a = 1;a < 10;a ++){
if(m<list.get(a)){
m=list.get(a);
locate=a;
}
}
tem = list.get(9);
list.set(9, m);
list.set(locate, tem);
for(int a = 0;a < 10;a ++){
System.out.print(list.get(a)+" ");
}
}
}
0.0分
0 人评分