TableUtilities.java 650B

1234567891011121314151617181920212223242526
  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 builder = new StringBuilder();
  10. for (int i = 1 ; i<= tableSize; i++) {
  11. for (int t = 1 ; t <= tableSize; t++) {
  12. builder.append(String.format("%3d |", (i*t)));
  13. }
  14. builder.append("\n");
  15. } return builder.toString();
  16. }
  17. }