+ 1

Loop

When looping I understand how to loop eg: 1 2 3 4 5 Using system.out.println and system.out.print process them horizontally. Let’s say I wanted to place 5 numbers per row till 25 how would I go upon so? Egx; 01234 56789

31st Aug 2018, 2:21 AM
Christian Vargas
Christian Vargas - avatar
2 Answers
+ 1
if you dont mind me asking, for (int j=i; j<i+5; ++j) is essentially what tells the program to group itself in 5 per line? or vice versa ?
31st Aug 2018, 7:39 AM
Christian Vargas
Christian Vargas - avatar
+ 1
In general: int columns = 5; int rows = 10; for (int i=0; i<rows; i++) { for (int j=0; j<columns; j++) System.out.print(j+i*columns); System.out.println(); }
31st Aug 2018, 1:07 PM
Mohammed