TableUtilities.java 1.2KB

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