首页 > 代码库 > 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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。