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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.