• 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 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
 
Attractive, successful people love 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