I'm trying to format the output of a multiplication table where you can only have 5 numbers/integers on one line. I'm trying this using a printf method in a for loop but it's not working so far.
Code:
System.out.println("Which multiplication table do you want to print?: ");
int number = input.nextInt();
int calculation;
System.out.println("Multiplication table: " + number + ":");
for (int i = 1; i <= 10; i++ ) {
calculation = number * i;
System.out.printf("%-5s ", calculation);
}
My output:
3 6 9 12 15 18 21 24 27 30
Output I'm trying to get:
3 6 9 12 15
18 21 24 27 30