TableUtilities.java 1.1KB

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