Write a Java program using for each loop.
Program1:class ForEachLoop1
{
public static void main(String args[])
{
int arr[]={13,20,30,40};
for(int i:arr)
{
System.out.println(i);
}
}
}
O/P:
13
20
30
40
Write a Java program using for each loop.
Program2:import java.util.*;
class ForEachLoop2
{
public static void main(String args[])
{
LinkedList<String> list=new LinkedList<String>();
list.add("Raju");
list.add("Hiten");
list.add("Kiran");
for(String s:list)
{
System.out.println(s);
}
}
}
O/P:
Raju
Hiten
Kiran
No comments:
Post a Comment