• 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

Question 2 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
What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select all correct answers.
public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args.length);
}
}

A.java
B.test
C.lets
D.3
E.4
F.5
G.6
Why are answers C & E correct ? I think it's A & G. Please explain.
 
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,
The answer to it again "test" and "4".
The reason is provided by yours truly in the earlier thread wherein you had posted your previous post. Please see my
comments at http://www.javaranch.com/ubb/Forum24/HTML/009712.html link.
Hope this would clear your doubts. ITS JAVA DONT FORGET THAT.
Ravindra Mohan.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the contrary the answers are:
args[0] = lets
and args.length = 4
 
Syed Hussain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please refer to the previous explanation
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bhaswati Karmakar:
What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select all correct answers.
public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args.length);
}
}

A.java
B.test
C.lets
D.3
E.4
F.5
G.6
Why are answers C & E correct ? I think it's A & G. Please explain.


In Java, the argument list starts after the class name.
So here "test" is the class name, after which we have the argument
list. There are total four arguments, so args.length = 4
And arg[0] = lets
args[1] =see
args[2] =what
args[3] =happens

 
Ravindra Mohan
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys there was a typo mistake in my earlier post.
The answer is "lets" and "4" .My explanation is
provided on the previous post in the thread http://www.javaranch.com/ubb/Forum24/HTML/009712.html
Hope the issue is clear now.
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
 
crispy bacon. crispy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic