Discuss / Java / 作业

作业

Topic source
public static void main(String[] args) {    String[] fields = { "name", "position", "salary" };    String table = "employee";    String select = buildSelectSql(table, fields);    System.out.println(select);    System.out.println("SELECT name, position, salary FROM employee".equals(select) ? "测试成功" : "测试失败");}static String buildSelectSql(String table, String[] fields) {    // TODO:    StringJoiner sj = new StringJoiner(", ");    for (String field: fields){        sj.add(field);    }    System.out.println(sj.toString());    StringJoiner sj2 = new StringJoiner(" ", "SELECT ", " FROM " + table);    sj2.add(sj.toString());    return sj2.toString();}

  • 1

Reply