0

so I'm scratching my head on how to flip the output which is a ruler....upside down any idea ? if you run the code you'll see the output I can't/don't how to post a sample here

public class Ruler {
   private static void drawMinorTicks(int line, int ticks) {
    if (ticks > 1) {
        drawMinorTicks(line, ticks - 1);
    }  
    if (line <= ticks) {
        System.out.print('|');
    } else {
        System.out.print(' ');
    }
    if (ticks > 1) {
        drawMinorTicks(line, ticks - 1);
    }
}

private static void drawSingleMajorTick(int line, int ticks, int label) {
    if (line <= ticks) {
        System.out.print('|');
    } else {
        System.out.print(label);
    }
}

private static void drawMajorTicks(int inches, int line, int ticks) {
    drawSingleMajorTick(line, ticks, 0);
    for (int i = 1; i <= inches; i++) {
        drawMinorTicks(line, ticks - 1);
        drawSingleMajorTick(line, ticks, i);
    }
}

private static void drawRuler(int inches, int ticks) {
    for (int i = 1; i <= ticks + 1; ++i) {
        drawMajorTicks(inches, i, ticks);
        System.out.println();
    }
}

public static void main(String[] args) {
    drawRuler(5, 5);
}

}

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
  • 2
    You're certainly very [keen](http://stackoverflow.com/questions/25942592/im-trying-to-print-this-ruler-horizontally-in-java) on [rulers](http://stackoverflow.com/questions/25954584/how-to-print-this-horizontally), aren't you? – David Conrad Sep 22 '14 at 21:07
  • Do not ask the same question more than once. – Kevin Panko Sep 22 '14 at 21:51

1 Answers1

1

Just iterate backwards in drawRuler()!

for (int i = ticks + 1; i > 0; --i) {
Chris
  • 694
  • 3
  • 18