以下Student类可直接使用。 public class Student { private int number; private String name; private String clazz; private int score; public Student(int number, String name, String clazz, int score) { this.number = number; this.name = name; this.clazz = clazz; this.score = score; } // 省略getter/setter方法 } 在以下类中,按需求编写方法,完成对STUDENTS集合的操作 public class StreamTest { private static final List STUDENTS = create(); private static final String CLAZZ1 = "软件1班"; private static final String CLAZZ2 = "软件2班"; private static List create() { Student s1 = new Student(2018008, "张扬", CLAZZ2, 66); Student s2 = new Student(2018005, "刘飞", CLAZZ1, 92); Student s3 = new Student(2018007, "李明", CLAZZ2, 42); Student s4 = new Student(2018006, "赵勇", CLAZZ2, 56); Student s5 = new Student(2018002, "王磊", CLAZZ1, 81); Student s6 = new Student(2018010, "牛娜", CLAZZ1, 78); List students = new ArrayList<>(); students.add(s1);students.add(s2);students.add(s3); students.add(s4);students.add(s5);students.add(s6); return students; } public static void main(String[] args) { // 调用实现方法测试 } // 实现方法 } 说明: 需求描述中的指定X,均指方法的参数 所有方法均有返回值,尝试直接编程return语句,基于stream操作流直接返回所需结果 如果返回集合,使用List集合类型 尝试使用简写 注意过滤代码格式 方法1,获取成绩小于等于指定分数,的全部学生
举一反三
- 【填空题】阅读程序写结果 public class Student { private static int sid = 0; private String name; int id; Student(String name) { this.name = name; id = sid++; } public void info() { System.out.println("My name is "+name+" No."+id); } public static void infoSta() { System.out.println(sid); } public static void main(String arg[]) { Student.sid = 100; Student st1 = new Student("huahua"); st1.sid = 2000; Student st2 = new Student("meimei"); st1.info(); st2.info(); } }
- 下面程序运行的结果是 struct Student { public int age; public string name; public Student(int age, string name) { this.age = age; this.name = name; } } class Program { static void Main(string[] args) { Student stu1 = new Student(18, "小方"); Student stu2 = new Student(24, "小刚"); stu2 = stu1; stu1.age = 30; stu1.name = "小燕"; Console.WriteLine("{1},{0}",stu2.age,stu2.name); } }
- (6-9)请阅读程序,写出程序运行结果。 class Phone{ private String name; private int price; public Phone(String name, int price) { this.name = name; this.price = price; } public String toString() { return ""+this.price; } } public class PhoneDemo { public static void main(String[] args) { StringBuffer sb=new StringBuffer(); Phone [] list=new Phone[3]; list[0]=new Phone("华为",3000); list[1]=new Phone("小米8",4000); list[2]=new Phone("vivo R10",2300); for(Phone p:list) sb.append(p); System.out.println(sb.toString()); } }
- This is ____ reading-room. A: the student's B: student's C: the students' D: students'
- 在C#中,下列代码的运行结果是( )(选一项)[br][/br] struct Student { public int age; public string name; public Student(int age,string name) { this.sge = sge; this.name = name; } } public class Test { static void Main() { Student stu1 = new Student(18,"小芳"); Student stu2 = new Student(24,"小刚"); stu2 = stu1; stu1.age = 30; stu1.name = "小燕"; Console.WriteLine(stu2.age); Console.WriteLine(stu2.name); } } A: 18 小芳 B: 18 小燕 C: 30 小燕 D: 30 小芳