Java-Get Array Values Using Loop

Get Array Value Using For Loop

Processing an entire array in a single operation is not possible. Each element of the array must be dealt separately. For this purpose loops are used. Though various loops are available in Java the most popular loop for array manipulation is the For-loop. We shall use a for loop for displaying the values of the elements of an array. For example, in the following program, the for loop displays the values of the elements of mark array. The loop is running while the value in the variable i is less than the size of the array.

Program 

Program  Source

public class Javaapp {
 
    public static void main(String[] args) {
     
        int[] mark = {10,30,50,70,90};
     
        for(int i=0;i<mark.length;i++)
        {
            System.out.println("mark["+i+"] = "+mark[i]);
        }
    }
}

Leave a Comment