简体   繁体   English

如何删除打印行之间的空格?

[英]How do I remove the space between printed lines?

I created this program to help draw a map in a text adventure I am creating. 我创建了这个程序,以帮助我在创建的文本冒险中绘制地图。 So far all it does is draw a black square of detentions you input. 到目前为止,它所做的只是绘制你输入的黑色方格的拘留。 Is there a way to remove the space between each line so there aren't white lines running through the square? 有没有办法去除每条线之间的空间,因此没有白线穿过广场?

Here is my code: 这是我的代码:

import java.util.Scanner;

public class MapGrid {

    static String createGrid(int x, int y) {
        String output = "";
        String block = new String("\u2588\u2588"); //A string of two unicode block symbols: ██

        if(x * y != 0) { //If neither x nor y is 0, a map of length x and height y will be returned
            for(int n = 1; n <= y; n++) {
                for(int i = 1; i <= x; i++) {
                    output += block;
                }
                output += "\n";
            }
        }
        return output;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        try(Scanner sc = new Scanner(System.in)) {

            System.out.println("Please enter the length of your map");
            int length = sc.nextInt();

            System.out.println("Please enter the height of your map");
            int height = sc.nextInt();

            System.out.println(createGrid(length,height));
        }
    }

}

This is what it prints when the user inputs 5 and 5: 这是用户输入5和5时打印的内容:

在此输入图像描述

I took a screenshot because it was hard to see what I was talking about with this font 我拍了一张截图,因为很难看出我用这种字体说的是什么

There is a small gap between each new line of blocks that makes it not look right. 每个新的块行之间有一个小的间隙,使它看起来不正确。 There probably isn't a way to fix this, but I thought I'd ask just in case there was. 可能没有办法解决这个问题,但我想我会问以防万一。

You probably want to redirect your System.out to another place. 您可能希望将System.out重定向到其他位置。
If you want to work with Swing then you can look here 如果你想使用Swing,你可以看看这里

Then it's the duty of the other place where you redirect it. 然后,你重定向它的另一个地方的责任。
But right now it's only a thing of your IDE ( Eclipse ). 但是现在它只是IDE( Eclipse )的一部分。 It is independent from your Java logic. 它独立于Java逻辑。

If your think serious about it. 如果你认真考虑它。 You don't want to play your text adventure in your Eclipse IDE. 您不想在Eclipse IDE中播放文本冒险。 So if you are using Windows the next question is if you want to use the Window command line . 因此,如果您使用的是Windows,则下一个问题是您是否要使用Window命令行 This may already be enough for you. 这可能已经足够你了。 But I still would recommend to make first thoughts about in which kind of window you want to have your text output 但我仍然建议您首先考虑在哪种窗口中输入文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM