Discuss / Java / 作业

作业

Topic source

shadowTy

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {

	public static void main(String[] args) {
		List<Person> persons = List.of(new Person("小明", 88), new Person("小黑", 62), new Person("小白", 45),
				new Person("小黄", 78), new Person("小红", 99), new Person("小林", 58));
		// 请使用filter过滤出及格的同学,然后打印名字:
		persons.stream().filter(s -> s.score >= 60).forEach(p -> System.out.println(p.name));;
	}
}

class Person {
	String name;
	int score;

	Person(String name, int score) {
		this.name = name;
		this.score = score;
	}
}

  • 1

Reply