123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
-
- public class TableUtilities {
- public static String getSmallMultiplicationTable() {
- StringBuilder table = new StringBuilder();
- String cell = "%3d |";
-
- for(int row=1; row<=5; row++){
- for(int i=1; i<=5; i++){
- int value = row * i;
- table.append(String.format(cell, value));
- }
- table.append("\n");
- }
- return table.toString();
- }
-
- public static String getLargeMultiplicationTable() {
- StringBuilder table = new StringBuilder();
- String cell = "%3d |";
-
- for(int row=1; row<=10; row++){
- for(int i=1; i<=10; i++){
- int value = row * i;
- table.append(String.format(cell, value));
- }
- table.append("\n");
- }
- return table.toString();
- }
-
- public static String getMultiplicationTable(int tableSize) {
- StringBuilder table = new StringBuilder();
- String cell = "%3d |";
-
- for(int row=1; row<=tableSize; row++){
- for(int i=1; i<=tableSize; i++){
- int value = row * i;
- table.append(String.format(cell, value));
- }
- table.append("\n");
- }
- return table.toString();
- }
- }
|