What will this method call print? public void patternGrid(int rows, int columns, char symbol) { for(int m = 0; m < rows; m++) { for(int n = 0; n < columns; n++) { System.out.print(symbol); } System.out.println(); } } patternGrid(3,4,'#');

Respuesta :

Answer:

This method will print three rows and four columns of "#"

####

####

####

Explanation:

Given the method patternGrid() as follows:

  1.    public static void patternGrid(int rows, int columns, char symbol)
  2.    {
  3.        for(int m = 0; m < rows; m++)
  4.        {
  5.            for(int n = 0; n < columns; n++)
  6.            {
  7.                System.out.print(symbol);
  8.            }
  9.            System.out.println();
  10.        }
  11.    }

Inside the method, there is a two-layer for-loop (Lind 3 - 11). In a two-layer for loop, A single iteration of the outer loop (Line 3) will be accompanied with n-iterations of inner loop (Line 5).

By calling the function patternGrid(3, 4, "#"), the 3 will be used as the rows number while 4 used as the columns number. The two-layer for loop will run for 3 x 4 times. The symbol "#" will be printed four times within the inner loop (Line 7) before it exists from the inner loop and print a new line (Line 10). This process will be repeated for 3 times and eventually give

####

####

####

ACCESS MORE
EDU ACCESS