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:
段 次 页 次 3月
Columns (2..20)? 5
| | | |
---+---+---+---+---
| | | |
---+---+---+---+---
| | | |
但我的方案却这样做:
段 次 页 次 3月
Columns (2..20)? 5
| | | |
---+---+---+---+---
| | | |
---+---+---+---+---
| | | |
---+---+---+---+---
这是该方案所期望的:
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.