TableUtilities.java 643B

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