How to determine a 2D-array dimension by input two integers separated by space? My method is use split function, convert string to integer and determine 2D array. Here is my code, however there is an syntax error.
Thanks
import java.util.Scanner;
public class inputtwointeger {
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
System.out.println("Enter integer separated by spaces: ");
String firstInput = input.nextLine();
String [] secondInput = firstInput.split(" ");
System.out.println("Numbers");
for(String n: secondInput)
{
System.out.print(firstInput+" "+secondInput);
}
//covert string into integer
int row = Integer.parseInt(secondInput[0]);
int column = Integer.parseInt(secondInput[1]);
// new a 2D array using two integer you input
int [][] array = new int[row][column];
}
//generate 2D array element in hand step by step
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
array[row][column] = input.nextInt();
System.out.print(Arrays.deepToString(array));
}
System.out.println();
}
}