Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Practice Questions

Work through AP Computer Science A practice 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 1,001–1,010 of 1,222
  1. 1001
  2. 1002
  3. 1003
  4. 1004
  5. 1005
  6. 1006
  7. 1007
  8. 1008
  9. 1009
  10. 1010

Question 1001

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 1002

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 1003

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 1004

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 1005

Multiple choice Using Text Files
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 1006

Multiple choice Using Text Files
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 1007

Multiple choice Using Text Files
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 1008

Multiple choice Using Text Files
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 1009

Multiple choice Using Text Files
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 1010

Multiple choice Using Text Files
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 1,001 of 1,222
Page 101 of 123