Java中用于填充表的For循环

Java中用于填充表的For循环,java,oop,Java,Oop,假设我有一个Java的表格式 0 1 2 |_E_|____|____| 0 |___|____|____| 1 其中,顶部的数字是列的索引,侧面的数字是行的索引。功能: add_at(x,y) 接受两个参数x和y,即x坐标和y坐标。我试图用一个for循环来填充表格,它从位置0,1开始,这是 0 1 2 |_E_|__x_|____| 0 |___|____|____| 1 标记为x,后跟0,2 0 1 2 |_E_|__x_|__x_| 0

假设我有一个Java的表格式

  0    1    2
|_E_|____|____| 0
|___|____|____| 1
其中,顶部的数字是列的索引,侧面的数字是行的索引。功能:

add_at(x,y)
接受两个参数x和y,即x坐标和y坐标。我试图用一个for循环来填充表格,它从位置0,1开始,这是

  0    1    2
|_E_|__x_|____| 0
|___|____|____| 1
标记为x,后跟0,2

  0    1    2
|_E_|__x_|__x_| 0
|___|____|____| 1
着手

  0    1    2
|_E_|__x_|__x_| 0
|_x_|____|____| 1

  0    1    2
|_E_|__x_|__x_| 0
|_x_|__x_|____| 1

  0    1    2
|_E_|__x_|__x_| 0
|_x_|__x_|__x_| 1
直到表格填写完毕,位置0,0除外,该位置用E标记

int max_row = 1;    //maximum row length is 1
int max_col = 2;    //maximum column length is 2

for (int x = 0; x<=max_row; x++) {
    for (int y = 1; y<max_col; y++) {
        this.add_at(x,y)
        }
    }
int max_row=1//最大行长度为1
int max_col=2//最大列长度为2

对于(int x=0;x将
y
更改为零(即填充所有行),并为(0,0)添加特殊条件


此外,这两种情况都应使用
。您可以按照以下操作,并且您可以根据需要更改代码:

    public class Table {
    public static void main(String[] args) {
      int maxRow = 4;    //maximum row length is 4
      int maxCol = 5;    //maximum column length is 5

      for (int x = 0; x<maxRow; x++) {
        for (int y = 0; y<maxCol; y++) {
          if (x==0 && y==0){
            System.out.print("| |");
            continue;
          }
          add_at(x, y);
        }
        System.out.println();
      }
    }

    public static void add_at(int x, int y) {


      System.out.print("|x|");
    }
  }
您可以从输出中看到屏幕截图:

我希望代码能帮助您

只使用

    public class Table {
    public static void main(String[] args) {
      int maxRow = 4;    //maximum row length is 4
      int maxCol = 5;    //maximum column length is 5

      for (int x = 0; x<maxRow; x++) {
        for (int y = 0; y<maxCol; y++) {
          if (x==0 && y==0){
            System.out.print("| |");
            continue;
          }
          add_at(x, y);
        }
        System.out.println();
      }
    }

    public static void add_at(int x, int y) {


      System.out.print("|x|");
    }
  }
| ||x||x||x||x|
|x||x||x||x||x|
|x||x||x||x||x|
|x||x||x||x||x|