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