• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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
 
It's just a flesh wound! Or a tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!