Sunday, February 22, 2009

source code to Demonstrate foreach loop



//sample example using foreach

package flowcontrol;

public class ForeachLoop {


public static void main(String[] args) {
int values[]={1,2,3,4,5};
String list[]={"ravi","giri","jani","chanti"};
for (String word : list)
System.out.println(word); // ravi , giri , jani , chanti

for(int i : values)
System.out.println(i); // 1, 2 , 3 , 4 ,5

}

}



0 comments:

Post a Comment