logo Practice-It logo

mystery2d5

Language/Type: Java 2D arrays array mystery
Author: Marty Stepp (on 2021/04/02)

Consider the following method:

            public List mystery(int[][] data, int n) {
                List result = new LinkedList();
                for (int i = 0; i < data.length; i++) {
                    if (data[i][n] % n != 0) {
                        result.add(data[i][n]);
                    }
                }
                return result;
            }
        

Suppose that a variable called grid has been declared as follows:

            int[][] grid = {{25, 72, 13, 12, 24, 18}, {16, 14, 4, 23, 15, 3}, 
                            {13, 29, 42, 52, 89, 18}, {25, 31, 35, 22, 66, 61}};
        

which means it will store the following 4-by-6 grid of values:

            25      72      13      12      24      18      
            16      14      4       23      15      3       
            13      29      42      52      89      18      
            25      31      35      22      66      61   
        

For each call below, indicate what value is returned. If the method call results in an exception being thrown, write "exception" instead.

mystery(grid, 2)
mystery(grid, 3)
mystery(grid, 5)

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.