W.A.P to Print Array in Java :-



public class Main {  
public static void main(String[] args)

{  
//Initialize array  
int [] arr = new int [] {1, 2, 3, 4, 5};  
System.out.println("Elements of given array: ");  
//Loop through the array by incrementing value of i  

for (int i = 0; i < arr.length; i++) {  
System.out.print(arr[i] + " ");  
}  
}  
}

Output:


Elements of given array: 
1 2 3 4 5

			

Algorithm:-

STEP 1: START
STEP 2: INITIALIZE arr[] = {1, 2, 3, 4, 5}.
STEP 3: PRINT "Elements of given array:"
STEP 4: REPEAT STEP 5 for(i=0; i<arr.length; i++)
STEP 5: PRINT arr[i]
STEP 6: END

Previous Next