public class Divisors {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i = 1; i <= N; i++) {
System.out.print(i+ ": ");
for (int j = 1; j <= N; j++) {
if (i % j == 0) {
System.out.print(j + " ");
}
}
System.out.println("");
}
}
}
Output:
$ java Divisors 15 1: 1 2: 1 2 3: 1 3 4: 1 2 4 5: 1 5 6: 1 2 3 6 7: 1 7 8: 1 2 4 8 9: 1 3 9 10: 1 2 5 10 11: 1 11 12: 1 2 3 4 6 12 13: 1 13 14: 1 2 7 14 15: 1 3 5 15