Verityprep
Question Bank · Unit 1

AP® Computer Science A Using Objects and Methods Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Using Objects and Methods, 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 371–380 of 681
  1. 371
  2. 372
  3. 373
  4. 374
  5. 375
  6. 376
  7. 377
  8. 378
  9. 379
  10. 380

Question 371

Multiple choice Using Objects

What is printed?

String s = "ABCDEFGHIJ";
int m = s.length() / 2;
String left = s.substring(0, m);
String right = s.substring(m);
String result = right + left;
System.out.println(result.substring(3, 7));
Pick an answer, then check it. The solution opens in a window.

Question 372

Multiple choice Primitive Types

What is printed?

double a = Math.pow(2, 10);
double b = Math.pow(2, 7);
System.out.println((a - b) + " " + (a / b));
Pick an answer, then check it. The solution opens in a window.

Question 373

Multiple choice Using Objects

What is printed?

String w1 = "banana";
String w2 = "band";
String w3 = "ban";
int r1 = w1.compareTo(w2);
int r2 = w2.compareTo(w3);
System.out.println((r1 > 0) + " " + (r2 < 0) + " " + (r1 + r2 > 0));
Pick an answer, then check it. The solution opens in a window.

Question 374

Multiple choice Using Objects

What is printed?

String p = "Java";
String q = p.substring(1) + p.length() + p.substring(0, 1);
System.out.println(q + " " + q.indexOf("4"));
Pick an answer, then check it. The solution opens in a window.

Question 375

Multiple choice Primitive Types

What is printed?

int a = 100, b = 3;
int q = a / b;
int r = a % b;
String s = "" + q + r + (q + r);
System.out.println(s);
Pick an answer, then check it. The solution opens in a window.

Question 376

Multiple choice Using Objects

What is printed by the following code segment?

String s = "programming";
String a = s.substring(0, s.indexOf("gram"));
String b = s.substring(s.indexOf("m") + 1, s.indexOf("ing"));
System.out.println(a.length() + b.length() + " " + a + b);
Pick an answer, then check it. The solution opens in a window.

Question 377

Multiple choice Primitive Types

What is printed?

int x = 47;
int a = x / 10;
int b = x % 10;
int y = b * 10 + a;
int z = y / 10 + y % 10;
System.out.println(z);
Pick an answer, then check it. The solution opens in a window.

Question 378

Multiple choice Primitive Types

What is printed?

int n = 1234;
int d1 = n / 1000;
int d2 = n / 100 % 10;
int d3 = n / 10 % 10;
int d4 = n % 10;
System.out.println(d4 * 1000 + d3 * 100 + d2 * 10 + d1);
Pick an answer, then check it. The solution opens in a window.

Question 379

Multiple choice Using Objects

What is printed?

String s = "PROGRAMMING";
int k = s.indexOf("RAM");
String t = s.substring(k, k + 5);
System.out.println(t + " " + t.indexOf("M"));
Pick an answer, then check it. The solution opens in a window.

Question 380

Multiple choice Using Objects

What is printed?

String s = "JAVA";
String t = "";
t = t + s.substring(3);
t = t + s.substring(1, 3);
t = t + s.substring(0, 1);
System.out.println(t + " " + t.indexOf("A"));
Pick an answer, then check it. The solution opens in a window.
Question 371 of 681
Page 38 of 69