Discuss / Java / 作业,已验证。

作业,已验证。

Topic source

Nobody52297

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

package com.itranswarp.learnjava;

import java.util.StringJoiner;

/**

 * Learn Java from https://www.liaoxuefeng.com/

 * 

 * @author liaoxuefeng

 */

public class Main {

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:

String str = " FROM " + table;

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

for (String i:fields) {

sj.add(i);

}

return sj.toString();

}

}


  • 1

Reply