1234567891011121314151617181920212223242526272829303132333435363738394041 |
-
- public class TableUtilities {
- public static String getSmallMultiplicationTable() {
-
- return getMultiplicationTable(5);
- }
-
- public static String getLargeMultiplicationTable() {
-
- return getMultiplicationTable(10);
- }
-
- public static String getMultiplicationTable(int tableSize) {
- StringBuilder table = new StringBuilder();
-
- for(int row=1; row <= tableSize; row++){
-
- for(int column=1; column<= tableSize; column++){
-
- table.append( String.format("%3d |" , column*row));
-
- }
-
- table.append("\n");
-
- }
-
- return table.toString();
- }
- }
-
- /**
- StringBuilder
- for loop row
- nested for loop coloumn
- append string
-
- Take note of how the multiplication table works
- **/
-
|