ProgrammingHardAccenture · Cognizant pattern

What will be the output of the following pseudocode (reversing the order of words in a sentence)?

What will be the output of the following pseudocode (reversing the order of words in a sentence)?
String s = "the sky is blue"
List words = split(s, " ")
reverse(words)
Print join(words, " ")
  1. A. blue is sky the
  2. B. the sky is blue
  3. C. eulb si yks eht
  4. D. blue sky is the

Correct answer: A. blue is sky the

Splitting on spaces gives {'the','sky','is','blue'}; reversing that list gives {'blue','is','sky','the'}, which joined with spaces is 'blue is sky the'.

More Pseudocode and Code Tracing questions

Exams that ask this topic