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

Trace both arrays public static void main(String[] args) { // initialize the arr

ID: 3607104 • Letter: T

Question

Trace both arrays

public static void main(String[] args) {

                      // initialize the array

                      int[] a = {85,95,80,100,90};

                      int n = a.length;

                      for (int i = 0; i < n-1; i++)

                                  for (int j = i+1; j < n; j++)

                                              if (a[j] < a[i])

                                              {

                                                          int temp = a[j];

                                                        a[j] = a[i];

                                                          a[i] = temp;

                                              }

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

                       

2. public static void main(String[] args) {

                      // TODO Auto-generated method stub

                      int[] f = new int[10];

                     

                      f[0] = 1;

                     

                     

                      for (int i = 1; i < 10; i++)

                                  f[i] = 2 * f[i-1];

                     

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

Explanation / Answer

1.

It sorts the data finally the result is 80 85 90 95 100.

it checking for the minimum element and at the each inner loop it has the array as

80 95 85 100 90

80 85 95 100 90

80 85 90 100 95

80 85 90 95 100

2.

Here initially f[0]=1 and for each value of array f is double the value of its previous value.

so here it prints 2 4 8 16 32 64 128 256 512.

It prints the array values from index 1 to 9, the value of array f in index i is 2i (i.e f[i]=2i).

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