集册 Java实例教程 使用数组初始化程序初始化数组的元素。

使用数组初始化程序初始化数组的元素。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

442
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用数组初始化程序初始化数组的元素。

public class Main 

{

   public static void main(String[] args)//来自 时代Java公众号 - nowjava.com

   {

      // initializer list specifies the initial value for each element

      int[] array = {132, 217, 614, 118, 915, 14, 910, 701, 60, 37};


      System.out.printf("%s%8s%n", "Index", "Value"); // column headings

   

      // output each array element's value 

      for (int counter = 0; counter < array.length; counter++)

         System.out.printf("%5d%8d%n", counter, array[counter]);

   }

}