itgle.com

Whichcodefragmentswillsucceedinprintingthelastargumentgivenonthecommandlinetothestandardoutput,andexitgracefullywithnooutputifnoargumentsaregiven?()CODEFRAGMENTa:publicstaticvoidmain(Stringargs[]){if(args.length!=0)System.out.println(args[args.length-1]);

题目

Whichcodefragmentswillsucceedinprintingthelastargumentgivenonthecommandlinetothestandardoutput,andexitgracefullywithnooutputifnoargumentsaregiven?()

CODEFRAGMENTa:

publicstaticvoidmain(Stringargs[]){

if(args.length!=0)

System.out.println(args[args.length-1]);

}

CODEFRAGMENTb:

publicstaticvoidmain(Stringargs[]){

try{System.out.println(args[args.length]);}

catch(ArrayIndexOutOfBoundsExceptione){}

}

CODEFRAGMENTc:

publicstaticvoidmain(Stringargs[]){

intix=args.length;

Stringlast=args[ix];

if(ix!=0)System.out.println(last);

}

CODEFRAGMENTd:

publicstaticvoidmain(Stringargs[]){

intix=args.length-1;

if(ix>0)System.out.println(args[ix]);

}

CODEFRAGMENTe:

publicstaticvoidmain(Stringargs[]){

try{System.out.println(args[args.length-1]);

}catch(NullPointerExceptione){}

}


相似考题