import java.lang.StringBuilder; public class TableUtilities { public static String getSmallMultiplicationTable() { StringBuilder sb = new StringBuilder(); for (int i = 1; i < 6; i++) { for (int j = 1; j < 6; j++) { int product = i*j; sb.append(" "); if (product < 10) { sb.append(" "); } sb.append(product + " |"); } sb.append("\n"); } return sb.toString(); } public static String getLargeMultiplicationTable() { StringBuilder sb = new StringBuilder(); for (int i = 1; i < 11; i++) { for (int j = 1; j < 11; j++) { int product = i*j; sb.append(" "); if (product < 10) { sb.append(" "); } else if (product > 99) { sb.deleteCharAt(sb.length() - 1); } sb.append(product + " |"); } sb.append("\n"); } System.out.println(sb.toString()); return sb.toString(); } public static String getMultiplicationTable(int tableSize) { StringBuilder sb = new StringBuilder(); for (int i = 1; i < tableSize + 1; i++) { for (int j = 1; j < tableSize + 1; j++) { int product = i*j; sb.append(" "); if (product < 10) { sb.append(" "); } else if (product > 99) { sb.deleteCharAt(sb.length() - 1); } sb.append(product + " |"); } sb.append("\n"); } System.out.println(sb.toString()); return sb.toString(); } }