public class ForLoopColorsExample3
{
public static void main(String args[])
{
// ForLoopColorsExample3
String colors[] = {"red", "yellow", "blue", "purple"};
for (int i = 0; i < colors.length; i++)
{
if (colors[i].equals("blue"))
{
System.out.println("name = " + colors[i]);
System.out.println("index = " + i);
}
}
}
}
name = blue index = 2
--- Output Ends ---
- javac ForLoopColorsExample3.java
- java ForLoopColorsExample3