12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable() {
  3. String str = "", strA = "";
  4. int multiply = 1;
  5. for(int i = 0; i < 5; i++)
  6. {
  7. for(int x = 1; x < 6; x++)
  8. {
  9. strA = strA.concat(String.format("%3d |", (x * multiply) ));
  10. }
  11. str = str.concat(strA + "\n");
  12. strA = "";
  13. multiply++;
  14. }
  15. return str;
  16. }
  17. public static String getLargeMultiplicationTable() {
  18. String str = "", strA = "";
  19. int multiply = 1;
  20. for(int i = 0; i < 10; i++)
  21. {
  22. for(int x = 1; x < 11; x++)
  23. {
  24. strA = strA.concat(String.format("%3d |", (x * multiply) ));
  25. }
  26. str = str.concat(strA + "\n");
  27. strA = "";
  28. multiply++;
  29. }
  30. return str;
  31. }
  32. public static String getMultiplicationTable(int tableSize) {
  33. String str = "", strA = "";
  34. int multiply = 1;
  35. for(int i = 0; i < tableSize; i++)
  36. {
  37. for(int x = 1; x <= tableSize; x++)
  38. {
  39. strA = strA.concat(String.format("%3d |", (x * multiply) ));
  40. }
  41. str = str.concat(strA + "\n");
  42. strA = "";
  43. multiply++;
  44. }
  45. return str;
  46. }
  47. }