Command line arguments and the length of the command line argument array

This is the question which I got "Write a program to read and display 2 command line arguments and the length of the command line argument array."

This is my answer in Java..Is this correct ?

    int length = args.length;

        for(int i = 0;i<length; i++)
            {
            System.out.println(args[i]);
            }
System.out.println("Length is " + args.length);
}

Upvotes: 0

Views: 5678

Answers (1)

Rudolf M&#252;hlbauer
Rudolf M&#252;hlbauer

Reputation: 2531

You should only display 2 arguments?

for(int i = 0; i< args.length && i < 2; i++)
{
  System.out.println(args[i]);
}
System.out.println("Length is " + args.length);

Upvotes: 3

Related Questions