Discuss / Java / 作业

作业

Topic source

Lumen.

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

import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {

        String[] fields = { "name", "position", "salary","id"};

        String table = "employee";

        String select = buildSelectSql(table, fields);

        System.out.println(select);

        System.out.println("SELECT name, position, salary, id FROM employee".equals(select) ? "测试成功" : "测试失败");

    }

    static String buildSelectSql(String table, String[] fields) {

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

        for(String n : fields){

            sj.add(n);

        }

        sj.add("FROM ");

        return sj.toString().replace(", F"," F");

    }

}


  • 1

Reply