How do I remove the space between printed lines?
Asked Answered
M

1

6

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:

enter image description here

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.

Mana answered 3/11, 2015 at 21:39 Comment(5)
The blank spaces between the lines are the spaces between the top of the character and the top of the line. Your issue is with the font, not the code.Inly
Thanks! But, how do I change the font? (Sorry i'm very new)Mana
Where do you have your output? Do you use an IDE?Forebear
I don't think you can if you're just printing to the console.Inly
@Bernd Ernst I program using eclipse - the output is in a console on the bottom of the window.Mana
F
5

You probably want to redirect your System.out to another place.
If you want to work with Swing then you can look here

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). It is independent from your Java logic.

If your think serious about it. You don't want to play your text adventure in your Eclipse IDE. So if you are using Windows the next question is if you want to use the Window command line. 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

Forebear answered 3/11, 2015 at 22:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.