Programming Quiz: Conditional Statements And Strings!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By KretschK
K
KretschK
Community Contributor
Quizzes Created: 9 | Total Attempts: 7,328
| Attempts: 381 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. An If statement always needs an Else statement.

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.

Submit
Please wait...
About This Quiz
Programming Quiz: Conditional Statements And Strings! - Quiz

Are you a programmer looking for a trivia quiz on conditional statements and strings? The quiz below is designed to help you see just how much you know... see moreabout the basic symbols in a string and how one should write a given code. Do give it a try and get a chance to refresh your understanding so far, Al the best!
see less

2. The condition in an If structure must always evaluate to _____.  

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.

Submit
3. Consider the following code Dim foo as String = "Chuck Berry" What is returned from the following statement: foo.EndsWith("ry")

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.

Submit
4. The comparison that checks if a variable called intAge is at least 18 is:

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.

Submit
5. 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".

Submit
6. 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.

Submit
7. String comparisons are always case sensitive.

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.

Submit
8. 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

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.

Submit
9. When comparing these two strings, the expression "Zebra" < "aardvark" is...

Explanation

In alphabetical order, "Z" comes after "a", so "Zebra" is greater than "aardvark". Therefore, the expression "Zebra"

Submit
10. 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

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.

Submit
11. 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.

Submit
12. 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?

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.

Submit
13. 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".

Submit
14. Consider the following variable Dim foobar as String = "Roy Orbison" What is returned by the following statement: foobar.substring(4, 4)

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".

Submit
15. 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".

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 08, 2014
    Quiz Created by
    KretschK
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
An If statement always needs an Else statement.
The condition in an If structure must always evaluate to _____. ...
Consider the following code...
The comparison that checks if a variable called intAge is at least 18...
Consider the following code...
Consider the following code...
String comparisons are always case sensitive.
Consider the following code...
When comparing these two strings, the expression "Zebra"...
Consider the following code...
Consider the following code...
Consider the following code: ...
Consider the following code...
Consider the following variable...
Consider the following code...
Alert!

Advertisement