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.

Questions 891–900 of 1,079
  1. 891
  2. 892
  3. 893
  4. 894
  5. 895
  6. 896
  7. 897
  8. 898
  9. 899
  10. 900

Question 891

Multiple choice Using Text Files
Assume the file data.txt contains: 4 7 2 9 5 8 public static int count() throws Exception { Scanner file = new Scanner(new…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 892

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 893

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 894

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 895

Multiple choice Recursion
Consider the following method: public static int recur(int n) { if (n <= 1) return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 896

Multiple choice Sorting And Searching
What is printed when the following main method is executed? public class Searcher { private int[] arr = {1, 3, 5, 8, 9}; public int mystery(int low, int high,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 897

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 898

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 899

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 900

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 891 of 1,079
Page 90 of 108