1.
Consider the following code
Dim foo as String = "Snoopy"
What is returned from the following statement: foo.trimright("y")
Explanation
The code snippet declares a variable "foo" of type String and assigns it the value "Snoopy". The "trimright" function is then called on the variable "foo" with the argument "y". This function removes any trailing occurrences of the specified character from the end of the string. In this case, since the character "y" is at the end of the string "Snoopy", it gets removed, resulting in the string "Snoop".
2.
Consider the following code
Dim foo as String = "Little Richard"
What is returned from the following statement: foo.remove(3,2)
Explanation
The code snippet declares a variable "foo" of type String and assigns it the value "Little Richard". The statement "foo.remove(3,2)" is called on the string "foo", which removes a specified number of characters starting from a specified position. In this case, it removes 2 characters starting from the 3rd position, resulting in the string "Lite Richard".
3.
Consider the following code
Dim foo as String = "Elvis Presley"
What is returned from the following statement: foo.length()
Explanation
The code declares a variable named "foo" and assigns it the value "Elvis Presley". The statement "foo.length()" is used to determine the length of the string stored in the variable "foo". In this case, the length of the string "Elvis Presley" is 13 characters, so the answer is 13.
4.
Consider the following code
Dim foo as String = "Patty Page"
What is returned from the following statement: foo.insert(6, "aa");
Explanation
The code declares a variable "foo" and assigns it the value "Patty Page". The statement "foo.insert(6, "aa")" inserts the string "aa" at index position 6 in the string "foo". Since the index position starts at 0, the character at index position 6 is the space between "y" and "P". Therefore, the resulting string is "Patty Paaage".
5.
Consider the following code
Dim foo as String = "Snoop Dogg"
What is returned from the following statement: foo.indexOf("g")
Explanation
The code is declaring a variable "foo" with the value "Snoop Dogg". The statement "foo.indexOf("g")" is used to find the index position of the first occurrence of the letter "g" in the string "foo". Since the letter "g" appears at index position 8 in the string "Snoop Dogg", the answer returned is 8.
6.
An If statement always needs an Else statement.
Correct Answer
B. False
Explanation
The statement is false because an if statement does not always need an else statement. An if statement is used to execute a block of code if a certain condition is true. However, if the condition is false, the code inside the if statement will not be executed. Therefore, an else statement is not always necessary.
7.
String comparisons are always case sensitive.
Correct Answer
A. True
Explanation
String comparisons in programming are case sensitive, meaning that the comparison takes into account the uppercase and lowercase letters. For example, "hello" and "Hello" would be considered different strings in a case-sensitive comparison. This is because the ASCII values of the uppercase and lowercase letters are different. Therefore, the correct answer is true.
8.
When comparing these two strings, the expression "Zebra" < "aardvark" is...
Correct Answer
A. True
Explanation
In alphabetical order, "Z" comes after "a", so "Zebra" is greater than "aardvark". Therefore, the expression "Zebra" < "aardvark" is true.
9.
The comparison that checks if a variable called intAge is at least 18 is:
Correct Answer
C. If intAge >= 18 Then
Explanation
This comparison statement checks if the value of the variable intAge is greater than or equal to 18. If the condition is true, it means that the intAge variable represents an age that is at least 18 years old.
10.
Consider the following code
Dim intA as Integer = 6
Dim intB as Integer = 0
Dim intC as Integer = -1
Is the following expression true or false?
If int A < int B OR intC < int B Then
Correct Answer
A. True
Explanation
The expression is true because it evaluates to true if either intA is less than intB or intC is less than intB. In this case, intA is 6 which is not less than intB (0), but intC is -1 which is less than intB. Therefore, at least one of the conditions is true, making the overall expression true.
11.
Consider the following code
Dim foo as String = "Chuck Berry"
Dim bar as String = "Chuck Schumer"
What is returned from the following statement: foo > bar
Correct Answer
B. False
Explanation
In this code, the variables "foo" and "bar" are both assigned string values. The statement "foo > bar" is comparing the two strings lexicographically. Since "Berry" comes after "Schumer" alphabetically, the expression "foo > bar" evaluates to False.
12.
Consider the following code
Dim foo as String = "Chuck Berry"
What is returned from the following statement: foo.EndsWith("ry")
Correct Answer
A. True
Explanation
The EndsWith method is used to check if a string ends with a specified value. In this case, the string "Chuck Berry" does end with "ry", so the statement foo.EndsWith("ry") would return True.
13.
Consider the following variable
Dim foobar as String = "Roy Orbison"
What is returned by the following statement: foobar.substring(4, 4)
Correct Answer
Orbi
Explanation
The given statement "foobar.substring(4, 4)" is using the substring method in the string variable "foobar". The method starts at index 4 and returns a substring of length 4. In this case, the substring "Orbi" is returned, which consists of the characters at indices 4, 5, 6, and 7 in the string "Roy Orbison".
14.
The condition in an If structure must always evaluate to _____.
Correct Answer
D. True or false
Explanation
The condition in an If structure must always evaluate to either true or false. In programming, the condition is a logical expression that determines whether the code block inside the if statement should be executed or not. If the condition evaluates to true, the code block is executed, otherwise it is skipped. Therefore, the condition can only have two possible outcomes: true or false.
15.
Consider the following code:
Dim s as Integer = txtName.Text.indexOf(" ")
if s = 0 Then
lblNick.Text = txtName.Text & "san"
Else
lblNick.Text.padleft("Dr. "
EndIf
If I type "Barak Obama" into the Name textbox, what is printed in the Nick label?
Correct Answer
B. Dr. Barak Obama
Explanation
The code first checks if there is a space in the text entered in the "Name" textbox. If there is no space (s = 0), it concatenates the text with "san" and displays it in the "Nick" label. However, if there is a space, it adds "Dr. " to the beginning of the text and displays it in the "Nick" label. So, if "Barak Obama" is entered, the code will add "Dr. " to the beginning and display "Dr. Barak Obama" in the "Nick" label.