Discuss / Java / 作业

作业

Topic source

ZUK郁文

#1 Created at ... [Delete] [Delete and Lock User]

public class demo18 {

  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) {

StringJoiner sj = new StringJoiner(" ", "SELECT ", table);

var s = String.join(", ", fields);

sj.add(s)

.add("FROM ");

return sj.toString();

}

}


  • 1

Reply