Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B Doubt p783, Q4 __A_V_.length

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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($);
}
}

invocation = java _ - A .

Output is A.

I thought it would be _-A. because it takes the args and plonks them into a String... iterates through these adding them to the string and spitting it out but I am clearly missing something here, is it to do with java syntax invocation that means the _ - do not reach the args method???

help very welcome, though I am sure I will figure it out eventually....
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note that the compilaador makes a parse ai provided that the declarac´┐Żes are valid. One _ is a valid statement, issue a lot of attention and he used the ability to vargs feature of java 5 in the statement of the main only to obstruct.
 
Robert Elbourn
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you saying that the "_ -" are dropped when parsing? or when copying into the String... ?
 
Robert Elbourn
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also I have 1.6 running in Eclipse

I put into the arguements (so not exactly from the command line)
java _ - A .

and this came out

-A.

now I've just realised that _ is the class definition so that isn't an arguement , so why does the - not get put into the string?
 
Robert Elbourn
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I had to change the arguements from
_ - A .
to

- A . and it looks like its coming with A. as the answer suggested, the only conclusion I can come up with is that - is used as an arguement for the virtual machine and therefore ignored as an arguement like
java blah - d or something? am I correct can anyone verify?
 
Robert Elbourn
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think I have it figured now, the ++x is pre-incrementing so the first character gets dropped ie. the -

the problem is I am sure I thought a previous question was pre-incrementing and it wasn't so .. nevermind,

anyway thanks for the help guys! :roll:
 
Yeah, but is it art? What do you think tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic