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

Finish the code below, writing the 3-deep nested loop needed to set all of the v

ID: 3681568 • Letter: F

Question

Finish the code below, writing the 3-deep nested loop needed to set all of the values in arr to 1.5 (hint: you will need 3 different loop variables to do this).

public class Lab8c public static void main (String[] args) int SIZE = Integer.parseInt (args [0]); /7 Create a 3-dimensional array of double where // the size of each dimension is SIZE: double table[] [] [] // [add code here]; // Fill in the table using a 3-deep nested loop so that // = 1.5 for a11 a,b,c // [add code here] table[a] [b] [c]

Explanation / Answer

public class Lab8c {

   public static void main(String[] args) {

       int SIZE = Integer.parseInt(args[0]);
       double table[][][] = new double[SIZE][SIZE][SIZE];

       for (int i = 0; i < SIZE; i++) {

           for (int j = 0; j < SIZE; j++) {

               for (int k = 0; k < SIZE; k++) {
                   table[i][j][k] = 1.5d;

               }
           }
       }
       System.out.println("TABLE is:");
       for (int i = 0; i < SIZE; i++) {

           for (int j = 0; j < SIZE; j++) {

               for (int k = 0; k < SIZE; k++) {
                   System.out.print(table[i][j][k] + " ");

               }
               System.out.println();
           }
           System.out.println();
       }

   }
}

OUTPUT:

TABLE is:
1.5 1.5 1.5
1.5 1.5 1.5
1.5 1.5 1.5

1.5 1.5 1.5
1.5 1.5 1.5
1.5 1.5 1.5

1.5 1.5 1.5
1.5 1.5 1.5
1.5 1.5 1.5

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