Given the following method public static int messAroundint a

Given the following method: public static int messAround(int[] a, int m, int n) {m = a[1] + n; a[3] + = 4; a[4] += 3; n = a[4]; System.out.println(n + \" \" + m); return a[0];} In addition, at the calling level, you have and What will be output to screen with a call ? 3 10 9 10, 9 3 10 9 3

Solution

Java Program:

In the method Call:

Initially,

Array a contains : [3, 6, 2, -1, 7];
m = 7; n = 3

--------------------------------------------------------------

1.   Statement: m = a[1] + n;
  
   m = 6 + 3 {a[1] = 3, n = 3}
   m = 9
  
---------------------------------------------------------------

2.   Statement: a[3] += 4;

   a[3] = a[3] + 4; {a[3] = -1}
   a[3] = -1 + 4
   a[3] = 3;
  
---------------------------------------------------------------

3.   Statement: a[4] += 3;

   a[4] = a[4] + 3; {a[4] = 7}
   a[4] = 7 + 3
   a[4] = 10;
  
---------------------------------------------------------------

4.   Statement: n = a[4];

   n = 10 {a[4] = 10}
  
--------------------------------------------------------------

5.   System.out.println(n + \" \" + m);

   Prints 10 9 to console {n = 10 from step 4, m = 9 from step 1}

--------------------------------------------------------------

Function returns value 3 to calling function.


Hence Output to a screen with call b = messAround(data, 7, 3); is 10 9

Correct option is (b) 10 9
   

 Given the following method: public static int messAround(int[] a, int m, int n) {m = a[1] + n; a[3] + = 4; a[4] += 3; n = a[4]; System.out.println(n + \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site