import java.util.*;
import java.io.*;
import java.math.*;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int w = in.nextInt(); // width of the strings
int h = in.nextInt(); // number of strings
char[][] answer = new char[w][h];
if (in.hasNextLine()) {
in.nextLine();
}
for (int i = 0; i < h; i++) {
String line = in.nextLine();
for(int j = 0; j < w; j++){
answer[i][j] = line.charAt(j);
System.out.print(answer[i][j]);
}
}
}
}
//抛出一个异常(。ArrayIndexOutOfBoundsException: Index 9 out of bounds for length 9)//基本上我想做的是说,例如输入是这样的:
3
3
…
…
…
//宽度为3,高度为3,我尝试用字符串的字符填充数组//我对Java有点陌生,但我喜欢解决这样的谜题,这个谜题简直要把我吃死了
不是100%确定你在问什么,但我猜你正在寻找这样的东西:
for (int i = 0; i < h; i++) {
String line;
while (true) {
line = in.nextLine();
if (line.length() == w)
break;
else
System.out.println("Please enter a string of length "+w);
}
for(int j = 0; j < w; j++){
answer[i][j] = line.charAt(j);
System.out.print(answer[i][j]);
}
System.out.println();
}