TableUtilities.java 648B

123456789101112131415161718192021222324252627
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable() {
  3. return getMultiplicationTable(5);
  4. }
  5. public static String getLargeMultiplicationTable() {
  6. return getMultiplicationTable(10);
  7. }
  8. public static String getMultiplicationTable(int tableSize) {
  9. StringBuilder sb = new StringBuilder();
  10. //int tableSize = 5;
  11. for(int i = 1; i <= tableSize; i++) {
  12. for(int j = 1; j <= tableSize; j++) {
  13. sb.append(String.format("%3d |", i * j));
  14. }sb.append("\n");
  15. }
  16. return sb.toString();
  17. }
  18. }