``` java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TableFormatter { public static void main(String[] args) { String filePath = "path/to/your/file.txt"; // 更換為實際文件的路徑 StringBuilder content = new StringBuilder(); // 讀取文件 try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { String line; while ((line = reader.readLine()) != null) { content.append(line); } } catch (IOException e) { e.printStackTrace(); } // 處理內容並輸出格式化表格 printFormattedTable(content.toString()); } private static void printFormattedTable(String content) { // 使用正則表達式匹配有特定格式的數據 Pattern pattern = Pattern.compile("\\(\\d+\\)|\\{\\d+\\}"); Matcher matcher = pattern.matcher(content); // 創建一個3x10的表格,初始化為"." String[][] table = new String[3][10]; for (String[] row : table) { Arrays.fill(row, "."); } int row = 0, col = 0; while (matcher.find()) { String match = matcher.group(); // 處理括號和大括號,使其符合要求的格式 if (match.startsWith("(")) { table[row][col++] = match; } else if (match.startsWith("{")) { if (col == 0 || table[row][col - 1].equals(".")) { table[row][col] = match; } else { table[row][col - 1] += match; } col++; } // 如果到達行尾,移動到下一行 if (col >= 10) { col = 0; row++; } // 如果行也填滿了,停止處理 if (row >= 3) { break; } } // 打印表格 for (int i = 0; i < 3; i++) { for (int j = 0; j < 10; j++) { System.out.printf("%-5s", table[i][j]); } System.out.println(); } } } ```