Easy Multiple Choice QuestionsΒΆ

These problems are mostly easier than what you will see on the AP CS A exam.

4-7-1: Given the following code segment, what is in the string referenced by s1?

String s1 = "xy";
String s2 = s1;
s1 = s1 + s2 + "z";






4-7-2: What is the value of len after the following executes?

String s1 = "Hey, buddy!";
int len = s1.length();




4-7-3: What is the value of pos after the following code executes?

String s1 = "ac ded ca";
int pos = s1.indexOf("d");





4-7-4: What is the value of s1 after the following code executes?

String s1 = "Hey";
String s2 = s1.substring(0,1);
String s3 = s2.toLowerCase();