Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用2D数组在java中创建文本边框_Java - Fatal编程技术网

使用2D数组在java中创建文本边框

使用2D数组在java中创建文本边框,java,Java,我有一点麻烦熨烫出我的终端为基础的游戏开始。我要做的是创建一个具有指定长度和高度的边框。下面是定义边界的代码块 public class Map { public static void drawMap(int width, int height) { int[][] map = new int[width][height]; int i = 0; for(width = 0; width < map.length; width++) {

我有一点麻烦熨烫出我的终端为基础的游戏开始。我要做的是创建一个具有指定长度和高度的边框。下面是定义边界的代码块

public class Map
{
public static void drawMap(int width, int height)
{
    int[][] map = new int[width][height];
    int i = 0;

    for(width = 0; width < map.length; width++)
    {
            System.out.print("-");
    for(height = 0; height < map[0].length; height++)
    {
        if(height < map[height].length)
        {
            System.out.print("\n|" + i++);
        }
    }
}
}
添加了i++以确保实际打印了多少列。我计划在它工作后取出的东西

for(int i=0; i<height;i++){
    for(int j=0; j<width; j++){
        if(i==0||i==height-1){
            System.out.print("-");
        }
        else{
            if(j==0||j==width-1){
                System.out.print("|");
            }
            else{
                System.out.print(" ");
            }
        }
    }
    System.out.print("\n");
}
如果您想变得更花哨,可以在角落处添加
+

+---+
|   |
+---+
我会让你想想怎么做的

如果您想变得更花哨,可以在角落处添加
+

+---+
|   |
+---+

我会让你想想怎么做的

你的问题是什么?你的代码有什么问题?如果不清楚是什么,你希望代码做什么。考虑发布一个预期输出的例子。我想你错过了内部for for循环中的另一个块。很抱歉,我希望代码做的是创建一个由破折号构成的边框。我发布的代码只会在最上面加上边框。你的问题是什么?你的代码有什么问题?如果不清楚,你希望代码做什么。考虑发布一个预期输出的例子。我想你错过了内部for for循环中的另一个块。很抱歉,我希望代码做的是创建一个由破折号构成的边框。我发布的代码只做最上面的边框。当我有权访问我的项目时,我会尝试这样做。当我有权访问我的项目时,我会尝试这样做
+---+
|   |
+---+