Skip to content

Instantly share code, notes, and snippets.

@ShawonAshraf
Created October 6, 2017 19:20
Show Gist options
  • Save ShawonAshraf/9c102a9035a0fee664f48e7eb097057d to your computer and use it in GitHub Desktop.
Save ShawonAshraf/9c102a9035a0fee664f48e7eb097057d to your computer and use it in GitHub Desktop.
2D variable dim array java
import java.util.Scanner;
public class VariableSize2DArray {
public static void main(String[] args) {
int row, col;
Scanner in = new Scanner(System.in);
// takes row and col size
// now you know the dim of array : row X col
row = in.nextInt();
col = in.nextInt();
// create array
int[][] array = new int[row][col];
// take input
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
array[i][j] = in.nextInt();
}
}
// done input
in.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment