I’m making a program that creates a grid with a number of lines and columns specified by the user.
I want the output to look something like this:
Lines (2..10) ? 3
Columns (2..20)? 5
| | | |
---+---+---+---+---
| | | |
---+---+---+---+---
| | | |
But my program does this instead:
Lines (2..10) ? 3
Columns (2..20)? 5
| | | |
---+---+---+---+---
| | | |
---+---+---+---+---
| | | |
---+---+---+---+---
This is what the program looks like:
String[] vertical = new String[columns-1];
String[] horizontal = new String[columns];
do
{
for(i = 0; i < vertical.length; ++i)
{
vertical[i] = (" |");
System.out.print(vertical[i]);
}
System.out.printf("%n");
for(i = 1; i < columns; ++i)
{
horizontal[0] = ("---");
horizontal[i] = ("+---");
}
if(horizontal.length > 0)
System.out.print(horizontal[0]);
for(int m = 1; m < horizontal.length; ++m)
System.out.print(horizontal[m]);
System.out.printf("%n");
++j;
} while (j <= lines - 1);
I know that I need to remove an horizontal line, the problem is that I don’t know how to. And sorry for the bad formatting.
Here you go…. and hell yes, your code is awful….. sorry for that, but true fact
EDIT: Here you have a way better implementation: