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 71–80 of 181
  1. 71
  2. 72
  3. 73
  4. 74
  5. 75
  6. 76
  7. 77
  8. 78
  9. 79
  10. 80

Question 71

Multiple choice Using Text Files
public static int readNumber() throws Exception { Scanner file = new Scanner(new File("missing.txt")); return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 72

Multiple choice Using Text Files
public static int count() throws Exception { Scanner file = new Scanner(new File("data.txt")); int count = 0; while (file.hasNextInt())…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 73

Multiple choice Using Text Files
A text file contains a single line: 42. What is printed by the following code? Assume sc is a properly constructed Scanner reading that file.
int x = sc.nextInt();
sc.close();
System.out.println(x + 8);
Pick an answer, then check it. The solution opens in a window.

Question 74

Multiple choice Using Text Files
A text file contains a single line: Hello World. What is printed?
String s = sc.nextLine();
sc.close();
System.out.println(s.length());
Pick an answer, then check it. The solution opens in a window.

Question 75

Multiple choice Using Text Files
A text file contains: apple banana cherry. What is printed?
String s = sc.next();
sc.close();
System.out.println(s);
Pick an answer, then check it. The solution opens in a window.

Question 76

Multiple choice Using Text Files
A text file contains: 3.5. What is printed?
double d = sc.nextDouble();
sc.close();
System.out.println(d * 2 + 1);
Pick an answer, then check it. The solution opens in a window.

Question 77

Multiple choice Using Text Files
A text file contains: true. What is printed?
boolean b = sc.nextBoolean();
sc.close();
if (b) {
    System.out.println("YES");
} else {
    System.out.println("NO");
}
Pick an answer, then check it. The solution opens in a window.

Question 78

Multiple choice Using Text Files
A text file contains: 7 3. What is printed?
int a = sc.nextInt();
int b = sc.nextInt();
sc.close();
System.out.println(a / b);
Pick an answer, then check it. The solution opens in a window.

Question 79

Multiple choice Using Text Files
A text file contains two lines:
hello world
goodbye
What is printed?
String s = sc.next();
String t = sc.nextLine();
sc.close();
System.out.println(s + t);
Pick an answer, then check it. The solution opens in a window.

Question 80

Multiple choice Using Text Files
A text file contains: 25. What is printed?
String s = sc.next();
sc.close();
int x = Integer.parseInt(s) + 5;
System.out.println(x);
Pick an answer, then check it. The solution opens in a window.
Question 71 of 181
Page 8 of 19