TableUtilities.java 869B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 table = new StringBuilder();
  10. for(int row=1; row <= tableSize; row++){
  11. for(int column=1; column<= tableSize; column++){
  12. table.append( String.format("%3d |" , column*row));
  13. }
  14. table.append("\n");
  15. }
  16. return table.toString();
  17. }
  18. }
  19. /**
  20. StringBuilder
  21. for loop row
  22. nested for loop coloumn
  23. append string
  24. Take note of how the multiplication table works
  25. **/