• 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

KB 791

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

Please expalin me why the output hear is A

the code

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 .
Self Test Answers 791

Thanks in advance
Suma
 
Ranch Hand
Posts: 38
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sumaraghavi ragha:
Hi Ranchers!!

Please expalin me why the output hear is A

the code

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 .
Self Test Answers 791

Thanks in advance
Suma


Hi,
I think this is what is happening in this code.
1) __A_V_.length holds the value 2 as the no. of command line args is 2 namely "-" and "A".
2) The variable x is intialized to 0 at the start of the for loop
3) The Test condition pre-increments it.So x becomes 1. and the test condition 1<2 gets satisfied and code flow enters the loop.
4) Now the value of __A_V_[x] i.e; __A_V_[1] is A(the second command line arg "A" whose index position is 1).This is printed.
5) Since the next test condition fails, the control exits the loop.
 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear

what about the "_".It's also their...

java _ - A .

Thanks
Suma
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"_" is a legal identifier and in this case it is name of the java file.
java _ is command for executing the program
 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to you both
 
reply
    Bookmark Topic Watch Topic
  • New Topic