CODE
----
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length > 1) // line 1.
System.out.println(i);
if(args.length > 0) // line 2.
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
A. test
B. test -1
C. 0
D. 1
E. 2
-----------
END OF CODE
Hi Vijayalakshmi,
The command for execution is
java test 2
So only one comand line argument.
The length of command-line argument array is now 1.
That's why the test at line 1. fails(args.length > 1)
The length is not greater than 1 but equal to 1.
For the same reason the test at line 2. succeeds (args.length > 0)
So the output 1.
Hope this helps.
------------------
Regards
---------
vadiraj
*****************
There's a lot of I in J.
*****************