我的账户
啄木鸟学院

专注软件测试菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

java-贺威栋-2021.03.11

[复制链接]
I5029学员认证 发表于 2021-3-11 21:53:56 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
package day05;

/*
1. 列表中存放着学生10次的成绩,去掉一个最高分,去掉一个最低分后,计算平均分。
2. 定义一个静态方法,类似python中切片的功能,参数1是一个整数列表,参数2是开始索引,参数3是结束索引。
返回包含开始、包含结束的子列表
比如传入 [1,2,3,4,5] , 1, 3 返回[2,3,4]
(1)、对参数做检查。
(2)、设计用例测试这个方法。

*/

import java.util.*;

public class HomeWork {
    // 1. 列表中存放着学生10次的成绩,去掉一个最高分,去掉一个最低分后,计算平均分。
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(Arrays.asList(80, 50, 60, 80, 90, 70, 100, 90, 80, 70));
        list.remove(Collections.max(list));
        list.remove(Collections.min(list));
        double sum = 0;
        for (int i = 0; i < list.size(); i++) {
            sum += list.get(i);
        }
        System.out.println("平均值是:" + sum / list.size());

        Scanner in = new Scanner(System.in);
        System.out.println("输入:");
        int str = in.nextInt();
        List<Integer> aa = new ArrayList<>(Arrays.asList(str));
        System.out.println(q(aa, 0, 3));

    }

    public static List<Integer> q(List<Integer> a, int b, int c) {
        List<Integer> alist = new ArrayList<>();
        for (int i = b; i < c + 1; i++) {
            alist.add(a.get(i));
        }
        return alist;
    }

}

回复

使用道具 举报

关注0

粉丝0

帖子27

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注软件测试菁英教育

客服电话:17792550360

客服时间:9:00-21:00

卓目鸟学苑 - 专注软件测试菁英教育!( 陕ICP备2025058934号-2 )

版权所有 © 西安菁英教育科技有限公司 2023-2026