Agony


私信TA

用户名:dzc21

访问量:53121

签 名:

CSDN博客:http://blog.csdn.net/qq_38712932

等  级
排  名 80
经  验 9189
参赛次数 0
文章发表 81
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

CSDN博客:http://blog.csdn.net/qq_38712932 个人博客:http://www.eternallyc.top/blog/index

解题思路:

注意事项:

参考代码:

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 人评分

  评论区