Programming Quiz: Conditional Statements And Strings!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By KretschK
K
KretschK
Community Contributor
Quizzes Created: 9 | Total Attempts: 6,717
Questions: 15 | Attempts: 319

SettingsSettingsSettings
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 about 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!


Questions and Answers
  • 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".

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

  • 6. 

    An If statement always needs an Else statement.

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 7. 

    String comparisons are always case sensitive.

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 8. 

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

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 9. 

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

    • A.

      If intAge > 18 Then

    • B.

      If intAge

    • C.

      If intAge >= 18 Then

    • D.

      If IntAge < 18 Then

    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.

    Rate this question:

  • 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

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 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

    • A.

      True

    • B.

      False

    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.

    Rate this question:

  • 12. 

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

    • A.

      True

    • B.

      False

    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.

    Rate this question:

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

    Rate this question:

  • 14. 

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

    • A.

      0 or 1

    • B.

      -1 or 0

    • C.

      Negative or positive

    • D.

      True or false

    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.

    Rate this question:

  • 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?

    • A.

      Obamasan

    • B.

      Dr. Barak Obama

    • C.

      Barak Obamasan

    • D.

      Dr. Obama

    • E.

      Baraksan

    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.

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.