Java Programming - Java.lang Class - Discussion
Discussion Forum : Java.lang Class - General Questions (Q.No. 4)
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 2Answer: Option
Explanation:
Arguments start at array element 0 so the fourth arguement must be 2 to produce the correct output.
Discussion:
33 comments Page 1 of 4.
Nijin said:
1 decade ago
Can anybody help me understanding this?
Sathish said:
1 decade ago
I can't understanding this concept please any one help me.
Abhijit said:
1 decade ago
args[0]=1,args[1]=3,args[2]=2,args[3]=3 and hence rip=args[3]=3
Akash Gupta said:
1 decade ago
This is very cconfusinig,i can't satisfied with your sugesition.
Sreekanth said:
1 decade ago
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.
So the answer is not a correct one.
Sundar said:
1 decade ago
The given answer is correct. I have tested the same.
Hope this will help you. Have a nice day!
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:
1 decade ago
I think [B] is correct answer!
The same with Sundar!
The same with Sundar!
Arindam said:
1 decade ago
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
"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:
1 decade ago
Anybody can explain this code clearly please I can't understand
Anvesh said:
1 decade ago
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers