# Printing out the relative lengths of the subdivisions on a ruler.

This program prints the relative lengths of the subdivisions on a ruler.

## Ruler.java

public class Ruler {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
// ruler of order 0
String ruler = " ";
// repeat N times
for (int i = 1; i <= N; i++) {
// concatenate a ruler of order 0, the number i, and a ruler of order 0
ruler = ruler + i + ruler;
// print out the final result
System.out.println(ruler);
}
}
}

## output

$ java Ruler 5
1
1 2 1
1 2 1 3 1 2 1
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1

## Questions answered by this page:

Recurrence relation that describes the length of a ruler
Prints the relative lengths of the subdivisions on a ruler.