You are here: Home / Topics / For each loop example 2 in Java

For each loop example 2 in Java

Filed under: Java on 2023-08-18 06:53:53

// for each loop example

class  ForEachTest 
{
public static void main( String args[ ] )
{
  int  ar[ ] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };

   for(int  x : ar) 
   {
 System.out.print(x + " "); 
 x = x * 10;  // no effect on nums
   }
  
   System.out.println();

   for(int x : ar) 
 System.out.print(x + " ");

}
}


Output:

10  20  30  40  50  60  70  80  90  100
10  20  30  40  50  60  70  80  90  100

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.