代码
提交代码
class NBATeam {
// 替换第一个球员方法
public void replaceFirstPlayer(String[] players, String playerName) {
// 替换第一个球员
System.out.println("将第一个球员替换:");
players[0] = playerName;
}
public static void main(String[] args) {
String[] players = {"詹姆斯", "科比", "杜兰特", "乔丹"};
System.out.println("球队中现有球员:");
for (String player : players) {
System.out.print(player + "\t");
}
System.out.println();
// 创建team对象并调用其替换球员方法
NBATeam team = new NBATeam();
team.replaceFirstPlayer(players, "皮蓬");
System.out.println("替换后球员:");
for (String player : players) {
System.out.print(player + "\t");
}
}
}
运行结果