CS 1713 Introduction to Computer Science Daily Problem

Suppose a is a two-dimensional array of integers. Write a code segment to set each element of the array to the sum of the row number and column number of the element.

Solution:

   for (int j=0;j<a.length;j++)
      for (int k=0;k<a[j].length;k++)
         a[j][k] = j + k;