logo Practice-It logo

ReferenceMystery

Language/Type: Java arrays reference semantics
Author: Marty Stepp (on 2020/04/16)

The following program produces 3 lines of output. Write each line of output below as it would appear on the console.

        import java.util.*;
        public class ReferenceMystery {
            public static void main(String[] args) {
                int x = 4;
                int y = 8;
                int[] data = {5, 10, 15};
                x = mystery1(y, data);
                System.out.println(y + " " + Arrays.toString(data));
                mystery2(x, y);
                System.out.println(x + " " + y);
            }
           
            public static int mystery1(int n, int[] numbers) {
                n = n + 100;
                numbers[2]--;
                System.out.println(n + " " + Arrays.toString(numbers));
                return numbers[1] * 2;
            }
        
            public static void mystery2(int x, int y) {
                x++;
                y = y * 3;
            }
        }
line 1
line 2
line 3

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.