//Assumption:
//Each number occupies max 3 characters
//1 for number separator i.e space
//2 for actual number
System.out.print(getSpace(3 * (num_of_lines - i - 1)));
for (int j = start_num ; j <= (start_num + i) ; j ++) {
//3 - chars required including actual number
//for single digit number prefix two spaces
//for double digit number prefix single space
System.out.print((j < 10 ? " " : " ") + j);
}
System.out.println();
}
}
private static String getSpace(int spaces) {
StringBuilder sb = new StringBuilder(); for (int i = 0 ; i < spaces ; i ++) {
sb.append(" ");
} return sb.toString();
}
}