Outputting values 1 to A, with B values per row (Java) -
public static void applicationb(int a, int b) { int number = 1; (int row = 0; row < a; row++) { (int col = 0; col < b; col++) { int output = number + row++; system.out.printf("% 4d", output); } // skip because of this? system.out.println(""); } }
it outputs = 20, b = 5
1 2 3 4 5 7 8 9 10 11 13 14 15 16 17 19 20 21 22 23
the correct output should be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
i cannot figure out how stop skipping 6, 12, , 18. doing horrible way? or on right track?
you incrementing row
in 2 places. also, easier have 1 loop, , output line break every b
elements (you can use i % b
test this).
Comments
Post a Comment