TableUtilities.java 875B

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