Multiple choice technology programming languages

Given: 11. public class Counter { 12. public static void main(String[] args) { 13. int numArgs = /* insert code here */; 14. } 15. } and the command line: java Counter one fred 42 Which code, inserted at line 13, captures the number of arguments passed into the program?

  1. args.count

  2. args.length

  3. args.count()

  4. args.length()

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Command-line arguments in Java are passed as a String array named args. The length of an array is accessed via the .length property (not a method like length()). So args.length gives the number of arguments.