Good evening!
There is such a task: Create a two-dimensional array N on M and fill it with an input from the keyboard. First of all, after the space, enter N and M, and then, depending on its size, enter what should be in each cell in this format:
Input format: 4 6 010101 111111 101011 101000 Get an array of sizes N by M - no problem. But how to fill it in exactly the format shown above? If I use 2 for loops, then only the first character in each line of each iteration of the loop reads me.
int N; int M; String[][] inputData; Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); inputData = new String[N][M]; for(int i=0; i<inputData.length; i++){ for(int j=0; j<inputData[i].length;j++){ inputData[i][j] = sc.nextLine(); } } I would be grateful for the help!
A similar solution for a simple array is here. But I could not use it for a two-dimensional array. How to fill an array of elements from the keyboard?