1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable() {
  3. StringBuilder builder = new StringBuilder();
  4. for (int i = 1; i <= 4; i++) {
  5. for (int j =1; j <= 4; j++) {
  6. String value = String.format("%3d |", i * j);
  7. builder.append(value);
  8. }
  9. builder.append("\n");
  10. }
  11. return builder.toString();
  12. }
  13. public static String getLargeMultiplicationTable() {
  14. StringBuilder builder = new StringBuilder();
  15. for (int i = 1; i <= 9; i++) {
  16. for (int j =1; j <= 9; j++) {
  17. String value = String.format("%3d |", i * j);
  18. builder.append(value);
  19. }
  20. builder.append("\n");
  21. }
  22. return builder.toString();
  23. }
  24. public static String getMultiplicationTable(int tableSize) {
  25. StringBuilder builder = new StringBuilder();
  26. for (int i = 1; i <= tableSize; i++) {
  27. for (int j =1; j <= tableSize; j++) {
  28. String value = String.format("%3d |", i * j);
  29. builder.append(value);
  30. }
  31. builder.append("\n");
  32. }
  33. return builder.toString();
  34. }
  35. }