//Assumption:
//Each number occupies max 4 characters
//1 for number separator i.e space
//3 for actual number
spaces = num - i - 1;
System.out.print(getSpace((4*spaces/2)));
public static long nCr(int n, int r) { return fact(n)/(fact(r) * fact(n-r));
}
public static long fact(long n) { if (n <= 1) { return 1;
} else { return n * fact(n-1);
}
}
private static void printNum(long num) {
//4 - chars required including actual number
//for single digit number prefix three spaces
//for double digit number prefix two space
//for three digit number prefix single space if (num < 10) {
System.out.print(" " + num);
} else if (num < 100) {
System.out.print(" " + num);
} else {
System.out.print(" " + num);
}
}
private static String getSpace(int spaces) {
StringBuilder sb = new StringBuilder(); for (int i = 0 ; i < spaces ; i ++) {
sb.append(" ");
} return sb.toString();
}
}