Identify the problems in the following code.

```
public class Test {
public static void main(String argv[]) {
System.out.println("argv.length is " + argv.length);
}
} ```
a. The program has a compile error because String argv[] is wrong and it should be replaced by String[] args.
b. The program has a compile error because String args[] is wrong and it should be replaced by String args[].
c. If you run this program without passing any arguments, the program would have a runtime error because argv is null.
d. If you run this program without passing any arguments, the program would display argv.length is 0.

d The parameter for the main method is an array of String. The declaration String argv[] is correct. When you run the program without passing arguments, argv is new String[0]. Thus, argv.length is 0 . See the NOTE box in the section, "Passing Arguments to Java Programs."

Computer Science & Information Technology

You might also like to view...

The Math method that returns the nearest whole number that is greater than or equal to its argument is:

(a) round (b) ceil (c) floor (d) all of the above

Computer Science & Information Technology

The Transfer command pastes a row of cells into a column, or a column of cells into a row.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology