一位数组:

public class TestDemo

{

    public static void main(String args[])

    {

        int [] arr = newint [5];

        Scanner input = new Scanner(System.in);

        for(intx = 0;x <arr.length;x++)

        {

            arr[x] = input.nextInt(); //手动赋值

        }

        printArray(arr);

       

//      for(int x = 0;x

//      {

//          System.out.print(arr[x]+"");   //打印输出

//      }

//     

       

       

        int [] data = newint []{1,2,3,4,5};

        System.out.println(data.length);

       

//      for(int x = 0;x < data.length;x++)

//      {

//          System.out.print(data[x]+"  ");

//      }

       

        printArray(data);

    }

   

    publicstaticvoid printArray(int [] arr)

    {  

        for(intx = 0;x < arr.length;x++)

            {

                System.out.print(arr[x]+" ");  //打印输出

            }

    }   //要想打印哪段代码,调用该方法即可!

}