-6

my code is this I have to manipulate stored data in the array to print individual elements of the array .ie the third and fifth team members names

     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 );
}
}
    }
Filburt
  • 17,626
  • 12
  • 64
  • 115
JINX
  • 5
  • 2
  • 3
    You forgot the part where you ask a question. In what way does this code not work as expected? What have you tried and where are you stuck? Also, formatting the code to be human-readable might help humans read your code. – David Mar 08 '15 at 00:35
  • the Java code displays all names with :The Team Players Names Are like this The Team Players Names Are:Mark Thompson" The Team Players Names Are:John Carey The Team Players Names Are:Pat Buckley The Team Players Names Are: Michael O'Connor etc but also i need to also print out the line"the third and fifth members names are "Pat Buckley","Finbarr Noonan" I've spent countless hours trying different ways and mouse pad has worn out but my question is how to solve the code.I'm new to coding but I've no idea how to solve it please help – JINX Mar 08 '15 at 11:53

1 Answers1

0

You can iterate like this:

 public static void  printStringArray(String[] players) { 
   for (int i =0; i < players.length;  i++)
    { 
       System.out.println(" The Team Players Names Are: " + players [i]); 
     } 
   } 

You should name variables self-descriptive also to avoid confusion.