47.0k views
4 votes
Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is called with changeArray(items, items[2]), what values are stored in items after the method has finished executing? public static void ChangeArray(int[] passedArray, int value) { passedArray[value] = 12; value = 5; }

a. 0, 2.5, 6. 12
b. 0, 2, 12, 6, 8
c. 0,2, 4, 6, 5
d. 2 46, 12

User Rommex
by
6.5k points

1 Answer

3 votes

Answer:

Non of the given options is correct.... The values stored in the array after the method ChangeArray(items,items[2]) is called are 0, 2, 4, 6, 12

Step-by-step explanation:

See complete java code and output below:

import java.util.Arrays;

import java.util.Scanner;

public class ANot {

public static void main(String[] args) {

int [] newarr = {0, 2, 4, 6,8};

ChangeArray(newarr, newarr[2]);

System.out.println(Arrays.toString(newarr));

}

public static void ChangeArray(int[] passedArray, int value) {

passedArray[value] = 12;

value = 5;

}

}

Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray-example-1
User VAr
by
6.1k points