1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import java.util.*;
  2. public class TableUtilities {
  3. public static String getSmallMultiplicationTable() {
  4. StringBuilder build = new StringBuilder();
  5. for(int i = 1;i <= 5;i++)
  6. {
  7. for(int j =1;j <= 5;j++)
  8. {
  9. int k = i * j;
  10. build.append(String.format("%3d |",k));
  11. }
  12. build.append("\n");
  13. }
  14. return build.toString();
  15. }
  16. public static String getLargeMultiplicationTable() {
  17. StringBuilder build = new StringBuilder();
  18. for(int i = 1;i <= 10;i++)
  19. {
  20. for(int j =1;j <= 10;j++)
  21. {
  22. int k = i * j;
  23. String x = String.format("%3d |",k);
  24. build.append(x);
  25. }
  26. build.append("\n");
  27. }
  28. return build.toString();
  29. }
  30. public static String getMultiplicationTable(int tableSize) {
  31. StringBuilder build = new StringBuilder();
  32. for(int i = 1;i <= tableSize;i++)
  33. {
  34. for(int j =1;j <= tableSize;j++)
  35. {
  36. int k = i * j;
  37. String x = String.format("%3d |",k);
  38. build.append(x);
  39. }
  40. build.append("\n");
  41. }
  42. return build.toString();
  43. }
  44. }