나는 자바가 처음이다. 나는 영어 통치자를 세로 대신 가로로 인쇄하려고 노력하고있다.나는이 통치자를 자바로 수평으로 인쇄하려하고있다.
샘플 출력을 시도했지만 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
}
}
}
제안 : 여기
코드입니다, (나는 그것을이 시간을 한) 코드 형식은 코드에서 원하는 출력을 제공하고 규칙을 읽어 Stack Overflow에 관한 질문 (How to Ask)을 게시하는 것에 대해 –'\ n'을 제거하고 | 함께 - 아마도 – bdavies6086
| | | | | | | | | | | | | | | | | 여기에 샘플 출력을 수행했습니다. 가장 작은 표시는 1/2^