解题思路:
注意事项:
参考代码:
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 人评分
C二级辅导-同因查找 (C语言代码)浏览:590 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:762 |
剔除相关数 (C语言代码)浏览:1053 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:778 |
C语言训练-数字母 (C语言代码)浏览:666 |
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:482 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:714 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1454 |
字符串的输入输出处理 (C语言代码)浏览:1081 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:414 |