This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

array question  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one can solve this question please...

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]);
}
}

1.The program will throw an ArrayIndexOutOfBounds exception.
2.The program will print "java test"
3.The program will print "java happens";
4.The program will print "test happens"
5.The program will print "lets happens"

Thanks in advance........
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try compiling it and running it yourself? Is there something in the output that is especially confusing?
Corey
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String array in the main() stores arguments passed on command line.It doesn't include "java" & "name of the program".
The no.of parameters,after the name of the program,gives u the array length .
Hope this helps,
args[0] = lets
args[args.length-1] = arr[4-1] = args[3] = happens.
[ May 16, 2002: Message edited by: geetha nagarajan ]
[ May 16, 2002: Message edited by: geetha nagarajan ]
 
Archana Agrawal
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lott Geetha, for your simple and valuable explaination.....
archana.
 
Archana Agrawal
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lott Geetha, for your simple and valuable explaination.....
archana.
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Archana.
Don't know if you noticed, but you are posting your msgs twice. Can you pls. address that...
thx
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Answer is quite Simple the fifth option is correct
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!