假设:
public static void printTriangle(int sideLength)
{
for (int i = 0; i <= sideLength; i++) {
for (int j = 0; j < i; j++){
System.out.print("[]");
}
System.out.println();
}
}
如何修改代码以打印sideLength = 3的方块?
[][][]
[][][]
[][][]
答案 0 :(得分:5)
像这样:
public static void printSquare(int sideLength)
{
for (int i = 0; i < sideLength; i++) {
for (int j = 0; j < sideLength; j++) {
System.out.print("[]");
}
System.out.println();
}
}