1. 程式人生 > >java數組的for遍歷

java數組的for遍歷

stat java數組 main static sys system length [] sta

class ArrayDome 
{
    public static void main(String[] args) 
    {
        int[] arr = {12,51,12,11}; 

        //順序遍歷
        for(int x = 0; x < arr.length; x++)
        {
            System.out.println(arr[x]);
        }


        //反向遍歷
        for(int x = arr.length-1; x >= 0; x--)
        {
            System.out.println(arr[x]);
        }


    }
}

java數組的for遍歷