Question 2911
Free response
Unit 4: Data Collections
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.
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);
Hello World. What is printed?
String s = sc.nextLine();
sc.close();
System.out.println(s.length());
apple banana cherry. What is printed?
String s = sc.next();
sc.close();
System.out.println(s);
3.5. What is printed?
double d = sc.nextDouble();
sc.close();
System.out.println(d * 2 + 1);
true. What is printed?
boolean b = sc.nextBoolean();
sc.close();
if (b) {
System.out.println("YES");
} else {
System.out.println("NO");
}
7 3. What is printed?
int a = sc.nextInt();
int b = sc.nextInt();
sc.close();
System.out.println(a / b);
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.