TableUtilities.java 1.2KB

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