【发布时间】:2019-02-20 17:29:38
【问题描述】:
在本练习中,我们必须使用 10 到 15 行和 20 到 30 列的二维数组绘制一个矩形,将矩形“#”的边框放入矩形“-”内。它必须看起来像这样:https://i.stack.imgur.com/IOqY6.png
到目前为止我的代码是这样的,但我需要一些帮助来修复它,因为我对这个练习有点迷茫:
public class Practica9{
public static void main(String[] args){
char [][] tablero = new char [10][20];
for (int i = 0; i < 10; i++){
for (int j = 0; j < 20; j++){
tablero [0][19] = #;
tablero [9][19] = #;
System.out.println (tablero[0][19]);
System.out.println (tablero[9][19]);
}
}
for (int i = 0; i < 10; i++){
for (int j = 0; j < 20; j++){
tablero [1][18] = -;
tablero [8][18] = -;
System.out.println (tablero [1][18]);
System.out.println (tablero [8][18]);
}
}
}
}
【问题讨论】:
-
您的输出看起来/与预期有何不同?
-
您必须将
#和-分别替换为'#'和'-'。
标签: java arrays multidimensional-array rectangles drawrectangle