TableUtilities.java 691B

123456789101112131415161718192021222324
  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 multTable = new StringBuilder();
  10. for(int i=1; i<=tableSize; i++){
  11. for(int j=1; j<=tableSize; j++){
  12. String number = String.format("%3d |", j*i);
  13. multTable.append(number);
  14. }
  15. multTable.append("\n");
  16. }
  17. return multTable.toString();
  18. }
  19. }