• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question on Array

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
What gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the one correct answer.
public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args[args.length-1]);
}
}

A.The program will throw an ArrayIndexOutOfBounds exception.
B.The program will print "java test"
C.The program will print "java happens";
D.The program will print "test happens"
E.The program will print "lets happens"
The correct answer is E. I don't understand why ? I think it's C. Please can anybody explain, why it is E.
Thanks.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The correct answer is E because in
java test lets see what happens
"java" is the command name for running the application
"test" is the class name u want to run
"lets see what happens" are the arguments for the application
args.length = 4
therfore
args[0] = lets
args[4-1] = happens
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhaswati,
Well to get the right answer you need to get the fundamentals
of C and C++ out in java .




The correct answer is E. I don't understand why ? I think it's C. Please can anybody explain, why it is E.



Dont worry its is not your fault many C and C++ still get stumpted because of "these" and many other differences that
exists between Java vis-a-vis C and C++.
Hope your querry is answered.
Ravindra Mohan
 
Bhaswati Karmakar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all for the explanation
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic