12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- // String.format();
- // %n
- import java.util.Formatter;
-
- public class TableUtilities {
- public static String getSmallMultiplicationTable() {
- StringBuilder table = new StringBuilder();
-
- for (int i = 1; i <= 5; i++) {
- for (int j = 1; j <= 5; j++) {
- table.append(String.format("%3s |", j * i));
- }
- table.append("\n");
- }
- //String tableLine = String.format("| %s |", table);
-
- System.out.println(table);
- return table.toString();
- }
-
- public static String getLargeMultiplicationTable() {
- StringBuilder table = new StringBuilder();
-
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++) {
- table.append(String.format("%3s |", j * i));
- }
- table.append("\n");
- }
- //String tableLine = String.format("| %s |", table);
-
- System.out.println(table);
- return table.toString();
-
- }
-
- public static String getMultiplicationTable(int tableSize) {
- StringBuilder table = new StringBuilder();
-
- for (int i = 1; i <= tableSize; i++) {
- for (int j = 1; j <= tableSize; j++) {
- table.append(String.format("%3s |", j * i));
- }
- table.append("\n");
- }
- //String tableLine = String.format("| %s |", table);
-
- System.out.println(table);
- return table.toString();
- }
- }
|