String CS Thinking Example 2

Follow the full solution, then compare it with the other examples linked below.

Example 2

medium
What is the result of concatenating 'Score: ' + STRING(95) + '%'?

Solution

  1. 1
    Step 1: STRING(95) converts the integer 95 to the string '95'.
  2. 2
    Step 2: Concatenation joins the three strings: 'Score: ' + '95' + '%'.
  3. 3
    Step 3: Result: 'Score: 95%'.

Answer

'Score: 95%'
String concatenation joins strings end to end. When mixing numbers and strings, the number must be converted to a string first (type casting) to avoid type errors.

About String

A data type that represents a sequence of characters (text), enclosed in quotation marks. Strings support operations like concatenation (joining), slicing (extracting substrings), searching, and comparison, and can contain letters, digits, spaces, and special characters.

Learn more about String โ†’

More String Examples