Question

Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for
Which of the following represents the final output of the code segment below? int k: int[]A; A new int[3]: fork-0; k<A.length
Consider the following code segment. int[]arm-{1, 2, 3, 4); for(int k-1; k<arr.length-1; k++) arr[k]-arr[k+1]: What are the c
Which of the following represents the final output of the code segment below? int[] a = {2, 2, 2, 21: int mul-1: for (int ite
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

We have a loop from i=10 to i < 30

And we're incrementing +3 every time

So, possible values of i are

10, 13, 16, 19, 22, 25, 28

We're adding i to values ArrayList if it gives 1 when we module with 5

So only 16 gives 1 when we module it with 5

So the answer is 16 which nums() method returns

2)

Initialized array with 3 elements

in the first for loop

for k=0 to k<A.length

A[k] = A.length-k;

means A[0] = 3-0 =3

A[1] = 3-1 = 2;

A[2] = 3-2 = 1;

A = [3,2,1];

In the second loop,

for k=0 to k<A.length-1

A[k+1] = A[k];

A[0+1] = A[0] = 3;

A[1+1] = A[1] = 3;

so, A = [3, 3, 3];

In the third loop we're printing array values

So the answer is 3 3 3

3)

We have arr ={1,2,3,4}

we have a loop

for k=1;k<arr.length-1;k++

arr[k] = arr[k+1]

arr[1] = arr[1+1] = 3

arr[2] = arr[2+1] = 4

arr = [1,3,4,4]

Answer is 1 3 4 4

4)

Here we have array a = {2,2,2,2}

mul = 1

In the loop we're taking each element and multiplying it with mul

So in first iteration mul = 1*2 = 2

second iteration mul = 2*2 = 4

third iteration mul = 4*2 = 8

fourth iteration mul = 8*2 =16

Answer is 16

Add a comment
Know the answer?
Add Answer to:
Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for(int i=10; i<30;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT