77 COUNT-VAR PIC 9 VALUE ZERO. 01 DATA-VAR PIC X(12). . . . INSPECT DATA-VAR TALLYING COUNT-VAR FOR LEADING “R” REPLACING FIRST “A” BY “2” AFTER INITIAL “Q” Refer to code above , If DATA-2 = RRAQADRRYRBB What are values for COUNT-VAR & DATA-VAR after the execution of INSPECT Statement ?

  1. 3 , RRAQ2DRRYRBB

  2. 0 , RR2Q2DRRYRBB

  3. 2 , RRAQ2DRRYRBB

  4. 2 , RR2QADRRYRBB


Correct Option: C

AI Explanation

To answer this question, let's go through the execution of the INSPECT statement step by step:

Given:

  • COUNT-VAR is initialized to 0.
  • DATA-VAR is initialized to "RRAQADRRYRBB".
  • The INSPECT statement is used to perform operations on DATA-VAR.
  1. Tallying COUNT-VAR for Leading "R":

    • This operation counts the number of occurrences of the leading character "R" in DATA-VAR.
    • Since the leading character in DATA-VAR is "R", COUNT-VAR is incremented by 1. COUNT-VAR becomes 1.
  2. Replacing First "A" by "2" After Initial "Q":

    • This operation replaces the first occurrence of "A" after the initial occurrence of "Q" with "2".
    • In DATA-VAR, the first occurrence of "A" after the initial "Q" is at the fourth position.
    • The "A" at the fourth position is replaced by "2". DATA-VAR becomes "RRAQ2DRRYRBB".

After the execution of the INSPECT statement, the values for COUNT-VAR and DATA-VAR are as follows:

COUNT-VAR: 1 (as it was incremented by 1 during the tallying operation) DATA-VAR: "RRAQ2DRRYRBB" (as the replacement operation was performed)

Therefore, the correct answer is option C) 1, RRAQ2DRRYRBB.

Find more quizzes: