我是java新手,我試圖水平打印英文標尺,而不是垂直打印,任何幫助都會被讚賞。我試圖在java中水平打印這個標尺
我試着把一個樣本輸出,但我需要10個聲望,但它非常類似於英國統治者。這裏是一個照片http://i.stack.imgur.com/y8beS.jpg
public class MyRuler
{
public static void main(String[] args)
{
drawRuler(3, 3);
}
public static void drawOneTick(int tickLength)
{
drawOneTick(tickLength, -1);
}
// draw one tick
public static void drawOneTick(int tickLength, int tickLabel)
{
for (int i = 0; i < tickLength; i++)
System.out.print("|\n");
if (tickLabel >= 0)
System.out.print(" " + tickLabel + "\n");
}
public static void drawTicks(int tickLength)
{ // draw ticks of given length
if (tickLength > 0)
{ // stop when length drops to 0
drawTicks(tickLength - 1); // recursively draw left ticks
drawOneTick(tickLength); // draw center tick
drawTicks(tickLength - 1); // recursively draw right ticks
}
}
public static void drawRuler(int nInches, int majorLength)
{ // draw ruler
drawOneTick(majorLength, 0); // draw tick 0 and its label
for (int i = 1; i <= nInches; i++)
{
drawTicks(majorLength - 1); // draw ticks for this inch
drawOneTick(majorLength, i); // draw tick i and its label
}
}
}
建議:格式化你的代碼(我做了這個時間),爲您提供從代碼需要的輸出,並讀取規則關於在堆棧溢出中發佈問題(如何問) – 2014-09-19 21:31:28
刪除'\ n'並替換|與 - 可能是 – bdavies6086 2014-09-19 21:34:50
| | | | | | | | | | | | | | | | | 我在這裏做 樣本輸出的公式是最小的標記以1/2^
2014-09-19 21:41:03