【发布时间】:2021-09-23 20:06:19
【问题描述】:
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) //bascially what im试图做它说例如输入是这样的:
3
3
...
...
...
//宽度为 3,高度为 3,我试图用字符串的字符填充数组 //我对 java 有点陌生,但我喜欢解决这样的难题,这个难题正在吞噬我
【问题讨论】:
-
你的答案数组应该是高度,宽度。
-
char[][] 答案 = 新 char[h][w];你可以创建高度,宽度的字符数组