首页 > 代码库 > 0926-----homework(3)

0926-----homework(3)

技术分享

 1 /** 2   *homework0926 3   *@author:kai li 4   */ 5 package com.kai.li.homework0926; 6 import java.util.List; 7 import java.util.ArrayList; 8 import java.util.Arrays; 9 10 /**11   *following class is client 12   */13 public class HomeWork0926{14     public static void main(String[] args)throws Exception{15         16         /**17           *question three18           */19 20         /*create data source*/21 22     List<Student> students=Arrays.asList(new Student("小明",18,100,"class05"),new Student("小黄",22,70,"class06"),new Student("小真",25,90,"class07"),new Student("小花",30,80,"class08"),new Student("tom",28,66,"class05"),new Student("jerry",24,100,"class04")); 23     24     /*operate*/25     int sumAge=students.stream().mapToInt(Student::getAge).sum();26     int sumScore=students.stream().mapToInt(Student::getScore).sum();27     System.out.println("学生的平均年龄是:"+sumAge/students.size()+",平均分数是:"+sumScore/students.size());28     }29 }30 /**31   *following class for question three32   *create data source class33   *student class34   */35 class Student{36     private String name;37     private int age;38     private int score;39     private String classNum;40     Student(String name,int age,int score,String classNum){41         this.name=name;42         this.age=age;43         this.score=score;44         this.classNum=classNum;45     }46     public String getName(){47         return name;48     }49     public int getAge(){50         return age;51     }52     public int getScore(){53         return score;54     }55     public String getClassNum(){56         return classNum;57     }58 }

 

0926-----homework(3)