Write a program that declares and initializes a 2D int array with 3 columns and 3 rows. Then, put the number 5 inside the middle square, and print out the value of the middle square. You can also initialize the array with 5 in the middle square, and don't forget to include zeros for the rest of the values.
top of page
bottom of page
class Main { public static void main(String[] args) { int [][] array1 = new int [3][3]; array1 [1][1] = 5; System.out.println(array1 [1][1]); int [][] array2 = {{0,0,0},{0,5,0}, {0,0,0}}; System.out.println(array2 [1][1]); } }
class Main { public static void main(String[] args) { int [][] array1 = new int [3][3]; array1 [1][1] = 5; System.out.println(array1 [1][1]); int [][] array2 = {{0,0,0}, {0,5,0}, {0,0,0}}; } }