Question 3001
Multiple choice
Unit 4: Data Collections
Consider a class
What is printed?
Student with constructor Student(String name, int grade) and methods getName() returning the name and getGrade() returning the grade. A text file contains:Alice,90Bob,85Carol,92What is printed?
ArrayList<Student> list = new ArrayList<Student>();
while (sc.hasNext()) {
String[] parts = sc.nextLine().split(",");
list.add(new Student(parts[0], Integer.parseInt(parts[1])));
}
sc.close();
String names = "";
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getGrade() > 88) {
names = names + list.get(i).getName() + " ";
}
}
System.out.println(names.length());
Pick an answer, then check it. The solution opens in a window.
DCorrect answer
Answer images

