Machine-translated by Google. Questions are authored in English.
Top

Discussion

public class Myfile 
{ 
    public static void main (String[] args) 
    {
        String biz = args[1]; 
        String baz = args[2]; 
        String rip = args[3]; 
        System.out.println("Arg is " + rip); 
    } 
}
Select how you would start the program to cause it to print: Arg is 2

 

  • A.java Myfile 222
  • B.
    java Myfile 1 2 2 3 4
  • C.java Myfile 1 3 2 2
  • D.
    java Myfile 0 1 2 3

Answer: C

Correct answer: java Myfile 1 3 2 2

The program prints args[3], and command line arguments are indexed from zero, so args[3] is the *fourth* one. With the arguments 1, 3, 2, 2 the fourth is 2, giving “Arg is 2”. The invocation with 0 1 2 3 would print 3, and the one with five arguments would also print 3 - both losing a place to the zero-based indexing.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.