Verityprep
Question Bank

AP® Computer Science A Practice Questions

Work through AP Computer Science A practice questions unit by unit, 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 2,921–2,930 of 3,140
  1. 2921
  2. 2922
  3. 2923
  4. 2924
  5. 2925
  6. 2926
  7. 2927
  8. 2928
  9. 2929
  10. 2930

Question 2921

Multiple choice Unit 4: Data Collections
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 2922

Multiple choice Unit 4: Data Collections
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 2923

Multiple choice Unit 4: Data Collections
A text file contains: 2.5. What is printed?
String s = sc.next();
sc.close();
double d = Double.parseDouble(s);
System.out.println(d + d);
Pick an answer, then check it. The solution opens in a window.

Question 2924

Multiple choice Unit 4: Data Collections
A text file contains:    hello    world    (with extra spaces). What is printed?
String s = sc.next();
String t = sc.next();
sc.close();
System.out.println(s.length() + " " + t.length());
Pick an answer, then check it. The solution opens in a window.

Question 2925

Multiple choice Unit 4: Data Collections
A text file is completely empty (contains no data at all). What is printed?
boolean result = sc.hasNext();
sc.close();
System.out.println(result);
Pick an answer, then check it. The solution opens in a window.

Question 2926

Multiple choice Unit 4: Data Collections
A text file contains a single line: 5 (followed by a newline). What is printed? int n =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2927

Multiple choice Unit 4: Data Collections
A text file contains: 7. What is printed? String s…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2928

Multiple choice Unit 4: Data Collections
A text file contains: 7. What is printed? String s =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2929

Multiple choice Unit 4: Data Collections
A text file contains: 7 2. What is printed? int a = sc.nextInt(); int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2930

Multiple choice Unit 4: Data Collections
A text file contains: 10 20 30. What is printed? String s =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2,921 of 3,140
Page 293 of 314