I'm new to java and I'm trying to print an english ruler horizontally instead of vertically, any help is appreciated.
I tried to put a sample output but I need 10 reputation but it's very similar to an english ruler. Here is a link of a photo https://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
}
}
}

If you're not going for a a special formula for presentation (i.e. this will likely not be scaled to an actual ruler) and just want the output to print horizontally, removing all instances of
\nfrom your code makes it print in a line.