ProgrammingHardCapgemini · Infosys
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
String s = "AAAAA", r = ""
Integer i = 0
while (i < length(s))
if (i + 1 < length(s) AND s[i] == 'A' AND s[i + 1] == 'A')
r = r + "B"
i = i + 2
else
r = r + s[i]
i = i + 1
end if
end while
Print r- A. BBBB
- B. BB
- C. BBA
- D. ABB
Correct answer: C. BBA
Replacements are made left to right without overlap: AA → B, AA → B, and the fifth A has no partner, so r = BBA.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (code(c) gives the ASCII code: 'A' = 65, 'a' = 97, '0' = 48; ^ is XOR) Integer x =…
- What will be the output of the following pseudocode? (| is OR, & is AND, << and >> are shifts) String s = "THE QUICK BROWN FOX" Integer…
- What will be the output of the following pseudocode? (Arrays are indexed from 0; abs gives the absolute value) Integer a[8] = {4, 3, 2, 7…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[4] = {3, 4, -1, 1}, n = 4 for (each i from 0 to…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[3] = {1, 3, 8}, b[4] = {2, 7, 9, 10}, c[7]…
- What will be the output of the following pseudocode? Integer m[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} for (each i from 0 to…