TableUtilities.java 1.1KB

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