The problem is in this line:
int size = scan.nextInt();
When your code asks to enter the size of the matrix, you enter a number, and then hit enter. The above code, however, only reads the number that you enter. It does not consume the enter (\n
character).
After your code consume the matrix size, your code does:
String[] input = scan.nextLine().split(" ");
which consumes the enter (\n
character), and then split it by space. This (scan.nextLine()
), of course, returns an empty string.
To fix it, instead of using:
int size = scan.nextInt();
use:
int size = scan.nextInt();
scan.nextLine();
No comments:
Post a Comment