Search | | Contact Us | Resource Center Login | Home|

What is the output of the following program?


import System.Collections

      players     ,@ArrayList
      lover       ,string
      beloved     ,string
      spin        ,int

      max         ,int, 4
      valentines  ,[max]a12, "Customers", "Synergy/DE", "Applications", "Synergex"
      February    ,int, 2

.define is_plural(a)    (a(trim(a):1) == 's')

      players = new ArrayList()
      for spin from 1 thru max
          lover = valentines[spin]
          if (is_plural(lover)) then
            players.insert(0, (string)atrim(lover))

      spin = February & 14 & 2012
      lover = (string)players[spin]
      if (spin < 2) then
        beloved = (string)players[spin + 2]
        beloved = (string)players[spin - 2]
      if (is_plural(lover)) then
        writes(1, lover + " love " + beloved)
        writes(1, lover + " loves " + beloved)

a. "Customers love Synergex"
b. "Synergex loves Customers"
c. "Synergy/DE loves Applications"
d. "Applications love Synergy/DE"
e. "Customers love Synergy/DE"

In celebration of Valentine's Day, today's quiz hosts an imaginary game of "Spin the Bottle" between Customers, Synergy/DE, Applications, and Synergex.

The first order of business in this game is to determine seating. The 'for' loop sorts the plural players (those ending with 's') to the top of the 'players' ArrayList, with the singular participants added to the end.
This results in the order: "Applications", "Customers", "Synergy/DE", "Synergex". Because plural items are inserted at the beginning, their order is reversed, while the singular items keep the same order at the end.

Next, we're ready to pick someone. Since 'February' is the name of a literal with a value of 2, the value of the expression 'February & 14 & 2012' is the same as '^x(0002) .band. ^x(000E) .band. ^x(07DC)', which is 0 (because 2 is a single bit, and 2012 doesn't have that bit set). The 0th element of players is "Applications". Remember that System.Collections.ArrayList uses a zero-based index. If we had used Synergex.SynergyDE.Collections.ArrayList instead, this would cause a subscript error.

Now, to pick the other partner, we'll take a shortcut and choose the party opposite to them. Since our index was 0 (which is less than 2), we add 2 and choose "Synergy/DE" (as we always should).

Thus, (d) is the correct answer. But as we all know, all of the above answers are true.