1234567891011121314151617181920212223
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable() {
  3. return getMultiplicationTable(5);
  4. }
  5. public static String getLargeMultiplicationTable() {
  6. return getMultiplicationTable(10);
  7. }
  8. public static String getMultiplicationTable(int tableSize) {
  9. StringBuilder sb = new StringBuilder();
  10. for (int column =1; column <= tableSize; column++) {
  11. for (int row =1; row<=tableSize; row++){
  12. sb.append(String.format("%3d |", row * column));
  13. }
  14. sb.append("\n");
  15. }
  16. return sb.toString();
  17. }
  18. }