What isfor (String sport: olympicSports) { System.out.println(sport); }


#1


what is the meaning of
for (String sport: olympicSports) {
System.out.println(sport);
}

Replace this line with your code.


#2

This is a foreach loop. You have a String array olympicSports and the String variable sport that will take on each value in the array.
Here is a normal for loop that does the same thing:

String sport = "";
for (int i = 0; i < olympicSports.length; i++)
{
   sport = olympicSports[i];
   System.out.println(sport);
}

comparing those two codes will hopefully help you understand it better.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.