1234567891011121314151617181920212223242526 |
-
-
- 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 i = 1; i <= tableSize; i++) {
- StringBuilder row = new StringBuilder();
- for (int j = 1; j <= tableSize; j++) {
- int number = i * j;
- String formatted = String.format("%3d |", number);
- row.append(formatted);
- }
- table.append(row + "\n");
- }
- return table.toString();
- }
- }
|