Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Using Text Files Clear filter

Questions 141–150 of 181
  1. 141
  2. 142
  3. 143
  4. 144
  5. 145
  6. 146
  7. 147
  8. 148
  9. 149
  10. 150

Question 141

Multiple choice Using Text Files
A text file contains: X,Y,Z. What is printed? String line = sc.nextLine(); sc.close(); String[] parts = line.split(",");…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 142

Multiple choice Using Text Files
A text file contains: 7,2. What is printed? String line = sc.nextLine(); sc.close(); String[] parts = line.split(",");…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 143

Multiple choice Using Text Files
A text file contains: one-two-three four-five. What is printed? String token =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 144

Multiple choice Using Text Files
A text file contains two lines: name:Alice score:95 What is printed? int score = 0; while (sc.hasNext()) { String[] parts =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 145

Multiple choice Using Text Files
A text file contains: 3,8,12. What is printed? String line = sc.nextLine(); sc.close(); String[] parts = line.split(","); int max =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 146

Multiple choice Using Text Files
A text file contains: 2026-03-25. What is printed? String line = sc.nextLine(); sc.close(); String[] parts =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 147

Multiple choice Using Text Files
A text file contains three lines: a,b,c,d e,f,g h,i What is printed? int total = 0; while (sc.hasNext()) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 148

Multiple choice Using Text Files
Consider the following class. public class Student { private String name; private int grade; public Student(String name, int grade) { this.name = name;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 149

Multiple choice Using Text Files

Consider the following Student class.

public class Student {
    private String name;
    private int grade;
    public Student(String name, int grade) { this.name = name; this.grade = grade; }
    public String getName() { return name; }
    public int getGrade() { return grade; }
}
A text file contains:
Alice,90
Bob,85
What 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();
System.out.println(list.get(1).getName());
Pick an answer, then check it. The solution opens in a window.

Question 150

Multiple choice Using Text Files
Consider a class Student with constructor Student(String name, int grade) and methods getName() returning the name and getGrade() returning the grade. A text file contains:
Alice,80
Bob,90
Carol,70
What 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();
int sum = 0;
for (int i = 0; i < list.size(); i++) {
    sum = sum + list.get(i).getGrade();
}
System.out.println(sum);
Pick an answer, then check it. The solution opens in a window.
Question 141 of 181
Page 15 of 19