📜  如何在java代码示例中打印数组的索引

📅  最后修改于: 2022-03-11 14:52:42.788000             🧑  作者: Mango

代码示例1
public class PrintArray {  
    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] + " ");  
        }  
    }  
}