permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp chapter 10 self test doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp chapter 10 self test doubt" Watch "scjp chapter 10 self test doubt" New topic
Author

scjp chapter 10 self test doubt

pooja sharma
Greenhorn

Joined: Oct 24, 2007
Posts: 14
import static java.lang.System.*;
class _ {
static public void main(String... __A_V_) {
String $ = "";
for(int x=0; ++x < __A_V_.length; )
$ += __A_V_[x];
out.println($);
}
}
And the command line:
java _ - A .

What is the result?
A. -A
B. A.
C. -A.
D. -A.
E. _-A.
F. Compilation fails.
G. An exception is thrown at runtime.

Answer is b.

please explain how this answer is coming.
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
for(int x=0; ++x < __A_V_.length; )
$ += __A_V_[x];

__A_V_.length = 2, __A_V_.length[0] = - and __A_V_.length[1] = A

1st iteration x = 1, 1 < 2 therefore $ = __A_V_[1] which is A next iteration x =2, 2 < 2 fails and therefore it prints A.
Vierda Mila
Ranch Hand

Joined: Feb 25, 2008
Posts: 61

__A_V_.length = 2, __A_V_.length[0] = - and __A_V_.length[1] = A


Hi Sridhar,

I think _A_V_.length = 3
__A_V[0] = -
__A_V[1] = A
__A_V[2] = .

and after iteration it will give output A.
[ April 29, 2008: Message edited by: Vierda Mila ]

SCJP 5
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
you are right Vierda..i still haven't got my new pair of glasses.
pooja sharma
Greenhorn

Joined: Oct 24, 2007
Posts: 14
Practically I had calculated the length of the __A_V_ and it is coming 3 so vierda's answer is more appropriate.
thanks for showing me the result step by step
Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

if the command line looks like
java _ - A .
_ is the name of class
then
__A_V[0] = -
__A_V[1] = A
__A_V[2] = .
so __A_V.length==3
and output should be A.

How can i delete my post? Now i can see where i was wrong so i don't have question ...




SCJP6 | http://programmerutilities.blogspot.com/
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
You dont need to delete your post, so that other can learn from it


Sage of The Monstrous Toad of Mount Myoboku
 
jQuery in Action, 2nd edition
 
subject: scjp chapter 10 self test doubt
 
Similar Threads
Compiling errata for K&B, SCJP 6
Doubt with Kathy sierra chapter 10
Can anyone explain this program briefly
ch10 q2
KB 791