140k views
4 votes
Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?

a. int count = args.length;
b. int count=0; while (!(args[count].equals(""))) count ++;
c. int count = args.length - 1;
d. int count = 0; while (args[count] != null) count ++;

1 Answer

1 vote

Answer:

The answer is a. int count =args.length

Step-by-step explanation:

Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?

a. int count = args.length;

b. int count=0; while (!(args[count].equals(""))) count ++;

c. int count = args.length - 1;

d. int count = 0; while (args[count] != null) count ++;

The answer is a. int count =args.length

args is a string array object, which contains set of all arguments. You can find the number of argument by using args.length.

User Netloh
by
4.7k points