Multidimensional Arrays & Passing Multidimensional Arrays to Methods
Wed Apr 21 2021 06:41:38 GMT+0000 (Coordinated Universal Time)
Saved by @ahmedqgqgq #java
import java.util.Scanner; public class Amazon { public static void main(String[] args) { int arr[][]=new int[3][]; arr[0]=new int[4]; arr[1]=new int[4]; arr[2]=new int[4]; arr[0][0]=1; arr[0][1]=2; arr[0][2]=3; arr[0][3]=4; arr[1][0]=10; arr[1][1]=20; arr[1][2]=30; arr[1][3]=40; arr[2][0]=50; arr[2][1]=60; arr[2][2]=70; arr[2][3]=80; } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int arr[][] = new int[3][4]; /* * arr[0]=new int[4]; * arr[1]=new int[4]; * arr[2]=new int[4]; */ arr[0][0] = 1; arr[0][1] = 2; arr[0][2] = 3; arr[0][3] = 4; arr[1][0] = 10; arr[1][1] = 20; arr[1][2] = 30; arr[1][3] = 40; arr[2][0] = 50; arr[2][1] = 60; arr[2][2] = 70; arr[2][3] = 80; } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int arr[][] = new int[][]{ {1,5,8}, {5,6}, {4}}; } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int arr[][] = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; System.out.println(arr.length); } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int arr[][] = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; System.out.println(arr.length); System.out.println(arr[0].length); System.out.println(arr[1].length); System.out.println(arr[2].length); } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int arr[][] = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; System.out.println(arr.length); System.out.println(arr[0].length); System.out.println(arr[1].length); System.out.println(arr[2].length); } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; for (int i = 0; i < arr[0].length; i++) { System.out.println(arr[i] + " "); } } } import java.util.Scanner; public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; for (int i = 0; i < arr[0].length; i++) { System.out.println(arr[0][i] + " "); } } } public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; for (int row = 0; row < arr.length; row++) { for (int col = 0; col < arr[row].length; col++) { System.out.print(arr[row][col] + " "); } System.out.println(); } } } public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; for (int row = 0; row < arr.length; row++) { for (int col = 0; col < arr[row].length; col++) { System.out.print(arr[row][col] + " "); } System.out.println(); } } } public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 5, 8 }, { 5, 6 }, { 4 } }; for (int[] r : arr) { for (int c : r) { System.out.print(c + " "); } System.out.println(); } } } public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 3, 5 }, { 2, 4, 6 } };// 2 X 3 transpose matrix. for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { System.out.print(arr[i][j] + " "); } System.out.println(); } } } public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 3, 5 }, { 2, 4, 6 } };// 2 X 3 transpose matrix. for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { System.out.print(arr[j][i] + " "); } System.out.println(); } } } public class Amazon { public static void main(String[] args) { int[][] arr = { { 1, 3, 5 }, { 2, 4, 6 } };// 2 X 3 transpose matrix. for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { System.out.print(arr[j][i] + " "); } System.out.println(); } } } public class Amazon { static void print(int a[][]) { for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.print(a[i][j] + " "); } System.out.println(); } } public static void main(String[] args) { int[][] arr = { { 1, 3, 5 }, { 2, 4, 6 } }; print(arr); } } public class Amazon { static void print(int a[][]) { for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.print(a[i][j] + " "); } System.out.println(); } } public static void main(String[] args) { int[][] arr = { { 1, 3, 5 }, { 2, 4, 6 } }; print(arr); } } public class Amazon { static int[][] get2Array() { int arr[][]=new int [2][3]; return arr; } public static void main(String[] args) { } }
Comments