我是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