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 2 of 4.
Dave said:
9 years ago
It was really true when we see that program executes that the fourth location must be 2.
Abhishek said:
9 years ago
Why D is not correct?
It also gives output as Arg is 2.
It also gives output as Arg is 2.
Sunil said:
9 years ago
Completely not getting output. Please someone explain it in detail.
Suneel said:
1 decade ago
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1.
At com.java.TestObj.main(TestObj.java:7).
At com.java.TestObj.main(TestObj.java:7).
Punam said:
1 decade ago
Not getting output.
Saurabh omer said:
1 decade ago
Command line arguments accept max index definition.....
a=args[4];
Then user must takes 4 values like java Myfile 1 2 3 4...
Another program,
a=args[3];
Then user must takes 3 values like java Myfile 2 3 4...
a=args[4];
Then user must takes 4 values like java Myfile 1 2 3 4...
Another program,
a=args[3];
Then user must takes 3 values like java Myfile 2 3 4...
Ted said:
1 decade ago
The answer is right. It is all about the COMMAND LINE ARGUMENTS.
The Java application = Myfile so,
When you write a command-line arguments.
Java Myfile .....
In this case we want the output to be: Args is 2.
Java Myfile 1322.
args[0] is 1.
args[1] is 3 which is biz.
args[2] is 2 which is baz.
args[3] is 2 and since rip is args[3], the answer is C.
The Java application = Myfile so,
When you write a command-line arguments.
Java Myfile .....
In this case we want the output to be: Args is 2.
Java Myfile 1322.
args[0] is 1.
args[1] is 3 which is biz.
args[2] is 2 which is baz.
args[3] is 2 and since rip is args[3], the answer is C.
Raju said:
1 decade ago
Guys Here question is asked about rip means args[3]. So don't think about args[0], args[1] or args[2]. Only think that in 4th args[] i.e. args[3] comes on which order.
String args[] position
biz = args[1] 0
baz = args[2] 1
rip = args[3] 2
And we can easily say that,
Whatever we will give the sequence no in input the 4th place should be 2nd position and here is only in option.
1 3 2 2
String args[] position
biz = args[1] 0
baz = args[2] 1
rip = args[3] 2
And we can easily say that,
Whatever we will give the sequence no in input the 4th place should be 2nd position and here is only in option.
1 3 2 2
Sindoori said:
1 decade ago
If command line args starts from 0123 then how args[1] is 3 and args[2] is 2. The answer should be 1232.
Narendra prajapati said:
1 decade ago
At cmd line args[] array has contain index. Which is start from 0 to no of arg. So if we are giving 11 2 3 56(including space).
So args[] array will take 11 on 0th index and 2 will take on 1st and 3 will take on 2nd and 56 on 3rd.
So args[] array will take 11 on 0th index and 2 will take on 1st and 3 will take on 2nd and 56 on 3rd.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers