TableUtilities.java 1.0KB

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