Ok. So this part is for getting the information...
private static int[] pointsToArray(BufferedReader in) throws IOException {
String[] arr = in.readLine().split(" ");
int[] array = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = Integer.parseInt(arr[i]);
}
return array;
}
And this is the main part:
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcases = Integer.parseInt(br.readLine());
int i = 1;
while (i <= testcases) {
int[] numbers = pointsToArray(br);
int rows = numbers[0];
int columns = numbers[1];
int[][] A = spiralMatrix(rows, columns);
System.out.println("Case " + i + ":");
for (int g = 0; g < rows; g++) {
for (int j = 0; j < columns; j++) {
if (rows * columns > 9 && rows * columns <= 99) {
System.out.print(String.format("%02d", (A[g][j])) + " ");
} else {
System.out.print(A[g][j] + " ");
}
}
System.out.println();
}
i++;
}
}