When you using while (++i < args.length) first value of i in boolean expression after ++ is 1. When you start program with one argument (like java c arg), program no output. When you start program with two arguments (like java c arg1 arg2), program output without last argument.
Correct code: class c { public static void main(String[] args) { int i = 0; while (i++ < args.length) { System.out.print(args[i]); }}}
hello lavanya ur program will give an output just try and hey vladimir program must give an exception ArrayIndexoutOfBound ur program is all right it shows output but leave first element output:bcdef
hai lavanya, you dont get an output because the While test is false so it never goes to the print statement. While(++i<args.length) ie. 1<1 is false. Hope this helps
If you worry you cannot work... If you work you need not worry
Hi, The prefix increment operator increments the value of the variable first and then uses the variable in the operation[or expression]. Now consider your case when u say ++i<args.length and the command line exp is java c abcd. here args.length will return 1. value of i before the if() loop is zero. when it encounters the line ++i < args.length, it first increments the value of i to 1 and then i takes part in the expression. Now 1 cannot be less than 1 and hence no output is shown.
I am not completely useless.<br />I can be used as a bad example.<br /> <br />SCJP 1.4