INSPECT MY-STRING TALLYING TALLY-1 FOR ALL 'A' BEFORE INITIAL SPACETALLY-2 FOR ALL 'A' AFTER INITIAL SPACEMY-STRING PIC X(17) VALUE "A P J ABDUL KALAM".TALLY-1 PIC 9(1) VALUE IS ZERO.TALLY-2 PIC 9(1) VALUE IS 5.VALUE IN TALLY-1 & TALLY-2 ARE

  1. 1,3

  2. 1,8

  3. 3,1

  4. none of the above


Correct Option: B

AI Explanation

To determine the values in TALLY-1 and TALLY-2, let's analyze the given code step by step.

The code defines two variables, MY-STRING and TALLY-1, and TALLY-2, with the following initial values:

  • MY-STRING is a 17-character alphanumeric string with the value "A P J ABDUL KALAM".
  • TALLY-1 is a 1-digit numeric variable with an initial value of zero.
  • TALLY-2 is also a 1-digit numeric variable with an initial value of 5.

The code then executes the INSPECT statement, which is used to count the occurrences of the letter 'A' in MY-STRING and update the values in TALLY-1 and TALLY-2 accordingly.

The INSPECT statement has the following format: INSPECT TALLYING FOR ALL BEFORE INITIAL SPACE TALLYING FOR ALL AFTER INITIAL SPACE.

In this case, the INSPECT statement is applied to MY-STRING, and the character to be counted is 'A'. The counts are stored in TALLY-1 and TALLY-2, respectively.

Let's go through each option to determine the correct values in TALLY-1 and TALLY-2:

Option A) 1,3 - This option is incorrect because TALLY-1 should count the occurrences of 'A' before the initial space, and TALLY-2 should count the occurrences of 'A' after the initial space. However, the given values in this option are reversed.

Option B) 1,8 - This option is the correct answer. TALLY-1 should count the occurrences of 'A' before the initial space, which is 1 in this case. TALLY-2 should count the occurrences of 'A' after the initial space, which is 8 in this case.

Option C) 3,1 - This option is incorrect because the values in TALLY-1 and TALLY-2 are reversed. TALLY-1 should count the occurrences of 'A' before the initial space, not after.

Option D) none of the above - This option is incorrect because the correct answer is option B, as explained above.

Therefore, the correct values in TALLY-1 and TALLY-2 are 1 and 8, respectively.

Find more quizzes: