For a list of students with marks, use streams to print the class average, the toppers (marks ≥ 90), the number who failed (< 40) and the names sorted by marks descending.
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
record Student(String name, int marks) { }
public class Main {
public static void main(String[] args) {
List<Student> cls = List.of(new Student("Asha", 92), new Student("Ravi", 38), new Student("Meena", 76), new Student("John", 95),
new Student("Zoya", 61), new Student("Neha", 29), new Student("Kiran", 84));
System.out.printf("average %.2f%n", cls.stream().mapToInt(Student::marks).average().orElse(0));
System.out.println("toppers " + cls.stream().filter(s -> s.marks() >= 90).map(Student::name).toList());
System.out.println("failed " + cls.stream().filter(s -> s.marks() < 40).count());
System.out.println("ranking " + cls.stream().sorted(Comparator.comparingInt(Student::marks).reversed()).map(Student::name).collect(Collectors.joining(" > ")));
}
}
average 67.86 toppers [Asha, John] failed 2 ranking John > Asha > Kiran > Meena > Zoya > Ravi > Neha
Each question about the data is one short pipeline over the same list.