ProgrammingModerateAccenture · Cognizant GenC Next

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
String s = "hello world of code"
Integer changes = 0
for (each i from 0 to length(s) - 1)
    if ((i == 0 OR s[i - 1] == ' ') AND s[i] is lower-case)
        s[i] = upper-case of s[i]
        changes = changes + 1
    end if
end for
Print s, changes
  1. A. Hello world of code 1
  2. B. HELLO WORLD OF CODE 16
  3. C. Hello World Of Code 4
  4. D. Hello World Of Code 3

Correct answer: C. Hello World Of Code 4

Every letter that starts the string or follows a space is capitalised: h, w, o, c. Output Hello World Of Code 4.

More Pseudocode and Code Tracing questions

Exams that ask this topic