集册 Java实例教程 初始化数组

初始化数组

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

590
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
初始化数组

public class Main {

  public static void main(String[] args) {
/* from nowjava.com - 时  代  Java*/

    // get array size from first command-line argument

    int arrayLength = 5;

    int[] array = new int[arrayLength];


    // get initial value and increment from command-line arguments

    int initialValue = 1;

    int increment = 2;


    // calculate value for each array element

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

      array[counter] = initialValue + increment * counter;
//NowJava.com 提 供

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


    // display array index and value

    
展开阅读全文