TableUtilities.java 919B

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