A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 编程青年 初级黑马   /  2019-9-18 19:48  /  542 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class Student {
    private String name;
    private int chinese;
    private int math;

    public Student() {
    }

    public Student(String name, int chinese, int math) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public void show(){
        System.out.println(name+"的语文成绩:"+chinese+",数学成绩:"+math+",总成绩:"+(chinese+math));
    }
}


import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        Student s1 = new Student("邓超",88,99);
        Student s2 = new Student("baby",85,78);
        Student s3 = new Student("邓超",86,50);
        ArrayList<Student> array = new ArrayList<>();
        array.add(s1);
        array.add(s2);
        array.add(s3);
        ArrayList<Student> array1=getSum(array);
        for (int i = 0; i < array1.size(); i++) {
            array.get(i).show();
        }


    }
    public static ArrayList<Student> getSum(ArrayList<Student> list){
        ArrayList<Student> array1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student stu=list.get(i);
            int chinese=stu.getChinese();
            int math=stu.getMath();
            if(chinese+math>160){
                array1.add(stu);
            }
        }
        return array1;
    }
}



0 个回复

您需要登录后才可以回帖 登录 | 加入黑马