【发布时间】:2019-02-15 05:12:29
【问题描述】:
所以我们要设计一本 ASCII 艺术书,我快完成了,但我想不出一点:“Building Java Programs”字样两边的间距
Here is what the book needs to look like
到目前为止,这是我的代码(为了便于帮助,我只显示需要间距帮助的方法。假设 drawLine() 将虚线均匀地绘制到 SIZE 常量的值)
//constant SIZE = 8
public static void drawBottom() {
//Dash line on top of the bottom portion of the book
drawLine();
//Printing first set of rightmost "/"'s
for (int i = 1; i <= SIZE; i++)
System.out.print("/");
System.out.println();
for (int i = 1; i <= SIZE / 2; i++) {
//Leftmost pipe
System.out.print("|");
// TO DO: Code label of book
// for (int j = 1; j <= ; j++) {
//
// }
//This loop is only here for example.
//To show I can fill the space but need
//the words in the space
for (int j = 1; j <= SIZE * 3; j++) {
System.out.print(" ");
}
//Rightmost pipe
System.out.print("|");
//"Pages" to right of label
for (int j = 1; j <= -2 * i + (SIZE + 2); j++) {
System.out.print("/");
}
//Move to draw next row
System.out.println();
}
//Dash line on very bottom of entire drawing
drawLine();
}
Here is my output (when SIZE = 8)
如何计算“Building Java Programs”文本块左右的间距?
我只知道当 SIZE = 8 时,两边各有一个空格
当SIZE = 10时,两边各有4个空格
当SIZE = 13时,两边各有8个空格
什么算法可以帮助我?
【问题讨论】: