"Weakness of attitude becomes weakness of character."
- Albert Einstein
4.
public class Myfile
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
Select how you would start the program to cause it to print: Arg is 2
[A].
java Myfile 222
[B].
java Myfile 1 2 2 3 4
[C].
java Myfile 1 3 2 2
[D].
java Myfile 0 1 2 3
Answer: Option B
Explanation:
Arguments start at array element 0 so the fourth arguement must be 2 to produce the correct output.
I can't understanding this concept please any one help me.
Abhijit said:
(Fri, Jun 17, 2011 10:56:39 AM)
args[0]=1,args[1]=3,args[2]=2,args[3]=3 and hence rip=args[3]=3
Akash Gupta said:
(Sat, Aug 27, 2011 05:55:20 PM)
This is very cconfusinig,i can't satisfied with your sugesition.
Sreekanth said:
(Tue, Aug 30, 2011 03:41:32 PM)
Actually if you check here as explained by args[0] = java args[1] = Myfile args[2] = 1 and args[3] = 3.
So the answer is not a correct one.
Sundar said:
(Thu, Sep 22, 2011 06:25:34 PM)
The given answer is correct. I have tested the same.
D:\Siva\Java>type Test.java
public class Test
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
D:\Siva\Java>javac Test.java
D:\Siva\Java>java Test 1 3 2 2
Arg is 2
D:\Siva\Java>
Hope this will help you. Have a nice day!
Asoka said:
(Tue, Jan 10, 2012 09:08:06 PM)
I think [B] is correct answer!
The same with Sundar!
Arindam said:
(Wed, Feb 1, 2012 08:24:44 AM)
When we want to run a java program then we always use
"java main_class_name"
But you use something more then that are stored in args[] array, which is also known as command line argument....
For ex- i write "java main_class_name Arindam Ghosh"
then program will run but 'Arindam' will stored in args[0] and 'Ghosh' will stored in args[1];
That's why here rip=args[3]=2
args[0]=1
args[1]=3
args[2]=2
args[3]=2
Subhan said:
(Fri, Aug 17, 2012 04:29:09 PM)
Anybody can explain this code clearly please I can't understand
Anvesh said:
(Wed, Nov 21, 2012 03:01:47 PM)
Yes dude,actually this is command line args, so normally arrays will be starting with zero, so given that answer c is correct, how means
args[1]=0;
args[2]=1;
args[3]=2;
So this args[3] value will be coming with we are using command line args. First you learn command line args carefully.