-2
       public string GenerateCardTokenOptimised()
        {
            int[] checkArray = new int[15];
            
            var cardNum = new int[16];
 
            for (int d = 14; d >= 0; d--)
            {
                cardNum[d] = _random.Next(0, 9);
                checkArray[d] = ( cardNum[d] * (((d+1)%2)+1)) % 9;
            }
 
            cardNum[15] = ( checkArray.Sum() * 9 ) % 10;
 
            var sb = new StringBuilder(); 
 
            for (int d = 0; d < 16; d++)
            {
                sb.Append(cardNum[d].ToString());
            } 
            return sb.ToString();
        }

It seems Rexx does not have the usual arrays in other languages so how can I implement this

Fnechz
  • 151
  • 8

1 Answers1

2

Rexx has stem variables. Stem variables are Associate arrays like Map<String, String> in Java and are used instead of arrays.

You can do

    do i = 1 to 10
       myArray.i = i
    end

you can also use strings as key in stem variables

    color = 'green'
    say "Color value: " colorLookup.color

You can also check if something is found

   false = 0
   true = 1

   found. = false /* initialize stem to false (0) */

   do i = 1 to 10
      square = i * i
      found.square = true
   end

   do i = 1 to 100
      if found.i = true then do
         say i "is a square"
      end
   end
Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
  • So are you saying that Java code can be converted into a similar Rexx program, thats what i want? – Fnechz Sep 26 '20 at 09:54
  • Yes, it can there is a function [Random](https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.ikja300/random.htm) function as well – Bruce Martin Sep 26 '20 at 23:45