TableUtilities.java 968B

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