Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the declarations: int[] list = new int[10]; show the elements of the array

ID: 3852215 • Letter: G

Question

Given the declarations:

int[] list = new int[10];

show the elements of the array list after the following statements are executed (exercises a, b, and c are independent. All use the same declaration.)

a) for(int i = 0; i < list.length; i++)

       list[i] = 10 - i;

b) for(int i = 0; i < list.length; i++){

   if (i <= 4)

        list[i] = -1;

   else

        list[i] = 1;

    }

c) for(int i = 0; i < list.length; i++){

    if(i % 2 == 0)

         list[i] = i;

    else

         list[i] = i + 1;

}

Explanation / Answer

a) for(int i = 0; i < list.length; i++)

       list[i] = 10 - i;

Output:

10 9 8 7 6 5 4 3 2 1

____________________

b) for(int i = 0; i < list.length; i++){

   if (i <= 4)

        list[i] = -1;

   else

        list[i] = 1;

    }

Output:

-1 -1 -1 -1 -1 1 1 1 1 1

__________________

C)

for(int i = 0; i < list.length; i++){

    if(i % 2 == 0)

         list[i] = i;

    else

         list[i] = i + 1;

}

Output:

0 2 2 4 4 6 6 8 8 10

_______________Thank Youi

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote