我的代码就是这个我必须操纵数组中的存储数据来打印数组的各个元素。第三和第五个团队成员名称
public class project
{
public static void main(String[]args)
{
String[]players = TheTeamPlayers();
printStringArray(players);
}
public static String[] TheTeamPlayers()
{
String[]players={"Mark Thompson","John Carey","Pat Buckley","MichaelO'Connor","Finbarr Noonan","Kevin Drogan","Ray Kelly","Jonathan Shannon","Ronan Linehan"};
return players;
}
public static void printStringArray(String[]strings)
{
for(String s : strings)
{
System.out.println(" The Team Players Names Are: " + s );
}
}
}
答案 0 :(得分:0)
你可以像这样迭代:
public static void printStringArray(String[] players) {
for (int i =0; i < players.length; i++)
{
System.out.println(" The Team Players Names Are: " + players [i]);
}
}
您应该将变量命名为自我描述,以避免混淆。