Question: Hi, I am new to java and i am stuck on this problem. Rewrite Fig. 7.2 so that the size of the array is specified

Hi, I am new to java and i am stuck on this problem.

Rewrite Fig. 7.2 so that the size of the array is specified by the first command-line argument. If no command-line argument is supplied, use 10 as the default size of the array. Now is our chance to run our program in command-line mode.

Here is the code that needs to be modified

public class InitArray {

public static void main(String[] args) { int[] array = new int[10]; System.out.printf("%s%8s%n", "Index", "Value");

for (int counter = 0; counter < array.length; counter++) { System.out.printf("%5d%8d%n", counter , array[counter]); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!