ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains
The procedure below counts the uppercase letters in the sentence "Hello World From AI". What is printed?
The procedure below counts the uppercase letters in the sentence "Hello World From AI". What is printed?
count = 0
for each character c
if c is an uppercase letter then count = count + 1
end for
Print count- A. 5
- B. 11
- C. 3
- D. 16
Correct answer: A. 5
The capitals are H, W, F, A and I, which is 5. Counting lowercase letters gives 12, counting the spaces gives 3, and counting all letters gives 17.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Strings are compared by dictionary order. The procedure below counts how many of ["apple", "mango", "kiwi", "banana", "mangoes"] are…
- A message of digits is decoded by mapping 1 to A, 2 to B, ..., 26 to Z, where a digit string may be split into one- or two-digit groups…
- A polynomial rolling hash of the string "abc" is computed as h = (h 31 + value) mod 1000, starting from h = 0, where value is the position…
- The string "bca" may have exactly one swap of two characters made. The procedure below finds the lexicographically smallest string…
- The phrase "the cat and the hat" is searched for the whole word "the" (counted as a separate word). The procedure below counts the…
- Strings are run-length compressed. The procedure below counts the number of runs in "aaabbc" (a run is a maximal block of equal…