Skip to content

Instantly share code, notes, and snippets.

@sanabanana-png
Created February 7, 2023 07:48
Show Gist options
  • Save sanabanana-png/67273bfbd3c5facfd3f5e3601879c804 to your computer and use it in GitHub Desktop.
Save sanabanana-png/67273bfbd3c5facfd3f5e3601879c804 to your computer and use it in GitHub Desktop.
public class ex53 {
public static void main(String[] args) {
printGrid(3, 6);
}
public static void printGrid(int rows, int cols) {
for (int line = 1; line <= rows; line++) {
for (int lineNum = line; lineNum <= (rows*cols) - rows; lineNum = lineNum + rows) {
System.out.print(lineNum);
System.out.print(", ");
}
System.out.print((((rows*cols)-rows))+line);
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment