Source code for ForLoopColorsExample3.java:

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);
			}
		}
	}
}

Output from ForLoopColorsExample3.java:

name = blue index = 2

--- Output Ends ---

NOTE:

You are reading previously generated output. You are not currently running the ForLoopColorsExample3 application at the momement. You need to compile and run the source code first.

To run this program:


Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR