June 2017
Beginner
1296 pages
69h 23m
English
... an array using command-line arguments.
3
4 public class InitArray {
5 public static void main( String[] args) {
6 // check number of command-line arguments
7 if ( args.length != 3) {
8 System.out.printf(
9 "Error: Please re-enter the entire command, including%n" +
10 "an array size, initial value and increment.%n");
11 }
12 else {
13 // get array size from first command-line argument
14 int arrayLength = Integer.parseInt(args[0]);
15 int[] array = new int[arrayLength];
16
17 // get initial value and increment from command-line arguments
18 int initialValue = Integer.parseInt(args[1]);
19 int increment = Integer.parseInt(args[2]);
20
21 // calculate value for each array element
22 for (int counter = 0; counter < array.length; counter++) {
23 array[counter] ...