Skip to content

Instantly share code, notes, and snippets.

@sorz
Created August 16, 2016 06:22
Show Gist options
  • Save sorz/d6a4986222fcc30642d92ac41be9aa29 to your computer and use it in GitHub Desktop.
Save sorz/d6a4986222fcc30642d92ac41be9aa29 to your computer and use it in GitHub Desktop.
public class MultiTable {
public static void printMulti(int row, int col) {
if (row == 0 && col == 0)
System.out.printf(" * ");
else if (col == 0)
System.out.printf("%4d ", row);
else if (row == 0)
System.out.printf("%4d ", col);
else
System.out.printf("%4d ", row * col);
if (col < 10)
System.out.printf("|");
}
public static void main(String[] args) {
for (int row=0; row<21; row++) {
for (int col=0; col<11; col++) {
if (row % 2 == 0) {
MultiTable.printMulti(row/2, col);
} else {
System.out.printf("-----");
if (col < 10)
System.out.printf("+");
}
}
System.out.println("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment