Multiple Choice Question

Quiz Guidelines

 

QID: 
460
Question: 

Which code fragments will print the last argument given on the command line to the standard output, and exit without any output and exceptions if no arguments are given?

1.
public static void main(String args[ ]){
if (args.length != 0)   System.out.println(args[args.length-1
}
2.
public static void main(String args[ ]){
try {    System.out.println(args[args.length-1]);    } 
catch (ArrayIndexOutOfBoundsException e) {     } 
}
3.
public static void main(String args[ ]){ 
int i = args.length;
if (i != 0) System.out.println(args[i-1]);
}
4.
public static void main(String args[ ]){ 
int i = args.length-1;
if (i > 0) System.out.println(args[i]);
}
5.
public static void main(String args[ ]){
try { System.out.println(args[args.length-1]); } 
catch (Null Pointer Exception e) {}
}

Select 3 options

A. 1
B. 2
C. 3
D. 4
E. 5

Q&A Set: 

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!